Results 1 to 10 of 10

Thread: Shooting at the Player

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Shooting at the Player

    Hi All,

    I am trying to make the enemy shoot the bullet in the Players direction :

    Bullet.Direction:=90-radtodeg(Math.arctan2(PlayerSprite.Y - Enemy.Y, PlayerSprite.X - Enemy.X));

    I found this online, it was used to turn a turret to face the Player ... it almost works.... but I think this is probably not what I want.

    Can anynone tell me how can I calculate Direction ( which is FxVelocity ) for the bullet so that it goes in the direction of the Player ?

    I guess I Need to calculate somehow the Direction which is based on the length it must travel to the Player and the Velocity of the Bullet .

    I tried to draw the Problem . I am not even sure if that is the correct way . I would Need to calculate like this if the Player X is smaller then Enemy X,
    and reversed if the Player X is greater then enemy X .

    UPDATE :

    I created a test Level with only one enemy,

    1st stationary... 2nd moving straight down , 3rd... moving left and right

    Bullet.Direction:=(90-radtodeg(Math.arctan2(PlayerSprite.Y - Enemy.Y, PlayerSprite.X - Enemy.X)))/12;

    I dont know why but if I divide the number which I get by twelve I get perfect hit on every Position for 1st test and 3rd test , on 2nd test when It goes straight down... after a while it shoots at incorrect angel...
    So I guess this arctan2 could still be the correct way.. but I am missing something here... something that I should be calculating with...but what....

    UPDATE 2:

    Bullet.Direction:=(90-radtodeg(Math.arctan2(PlayerSprite.Y - Self.Y, PlayerSprite.X - Self.X)))/12;

    Self.X and Self.Y is the proper way... if I have multiple enemy ships.... this works... but the precision is still a bit off....

    Please help.

    THanks. Robert
    Attached Images Attached Images
    Last edited by robert83; 08-12-2015 at 02:41 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •