Search Unity

How to make enemies aim and shoot at you in advance?

Discussion in '2D' started by captnhanky, Feb 28, 2019.

  1. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Hi!

    I am a beginner in unity and a big fan of the williams defender arcade game.
    This game from 1980 set standards in 2D enemy behavior never seen before and even after until now.

    One of this great behaviors is that some enemies can take your flight speed and direction into calculation and shoot their bullets in advance, so that when you continue to fly in a certain direction and not changing your speed the bullet will hit you.
    The enemies can even vary the shooting speed to compensate their late detection of you.

    It is like when a player tries to hit an enemy..he has to aim and shoot at the enemy in advance to hit it.
    I need it the other way around.

    How is this working and how can I implement this?

    Thanks a lot!


    Here you can see it clearly at 0:09 1:21 2:08 4:30
     
    Last edited: Feb 28, 2019
  2. pod11

    pod11

    Joined:
    Jan 6, 2019
    Posts:
    60
    Assuming you are using rigidbody to move player, you have velocity of a player, you can use it to predict where player would have been after certain amount of frames.
    Using raycasts you may measure distance betwen player and enemy, or enemy and projected position of player after certain amount of frames.
    Having bullet speed ,player speed ,distance betwen player-enemy, and distance betwen enemy and where player would have been after certain amount of frames you can create offset to aiming targets.
    -------
    Some functions that may be usefull are:
    vector3.Movetowards();
    Vector3.magnitude / vector3.sqrmagnitude
     
  3. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    pod11

    Thank you, will have a look at this.

    My fast solution is to have 2 different enemies, where one shoots at your exact position and the other one adds a fixed value to your current x position.
    So when you don´t move you will be hit, and when you move at full speed you also will be hit.
     
    Last edited: Mar 2, 2019