Computer Science Canada

Calculate angle between two points

Author:  Bored [ Sun Mar 20, 2005 6:55 pm ]
Post subject:  Calculate angle between two points

Heres the deal. I have a two player version of a little space game here. I want to make a one player version by making the second player into an ai. I thought i'd go about it by fist having him chase you and try to shoot you and work my way from there. To hav him chase you he must be able to able to calculate the angle at which the other player is so he will know which way to travel. What i need from you guys is how to do this. Just for reference upwards is 0 degrees and the controls are
P1:
Up=Forward
Down=Backward
Left=Turn Left
Right=Turn Right
Ctrl=Sharp Turn
Shift=Shoot
Enter=Change Weapon
P2:
W=Forward
S=Backward
A=Turn Left
D=Turn Right
E=Sharp Turn
Tab=Shoot
Q=Change Weapon

Author:  Mr. T [ Sun Mar 20, 2005 7:09 pm ]
Post subject: 

nice little game, i like the way the bullets bounce off the planet thing...
one way of fixing the game, would be by decreasing the amount of hits it takes to destroy the planet... it took me 5 minutes of firing to destroy one Surprised

Author:  Cervantes [ Sun Mar 20, 2005 7:16 pm ]
Post subject: 

Behold! The wonders of zylum approach!

zylum:

%credit: zylum
fcn GETANGLE (x1, y1, x2, y2 : real) : real
    var dx, dy, ratio, angle : real
    dx := x2 - x1
    dy := y2 - y1
    if dx not= 0 then
        ratio := dy / dx
    else
        ratio := dy / 0.00000001
    end if
    angle := arctand (abs (ratio))
    if dx < 0 then
        angle := 180 - angle
    end if
    if dy < 0 then
        angle := 360 - angle
    end if
    result angle
end GETANGLE


lol Very Happy

Author:  Bored [ Sun Mar 20, 2005 7:53 pm ]
Post subject: 

thx alot for the help crevetes and for pwned the game is sopposed to take a bit of time and thats why the bases are so hard to destroy

Author:  Mr. T [ Sun Mar 20, 2005 8:15 pm ]
Post subject: 

his name is cervantes

Author:  Mr. T [ Sun Mar 20, 2005 8:15 pm ]
Post subject: 

Bored wrote:
thx alot for the help crevetes...


his name is Cervantes Rolling Eyes

Author:  [Gandalf] [ Mon Mar 21, 2005 7:39 pm ]
Post subject: 

Confused spam? I refreshed a few times, and it didn't go away..?

Cool game btw! Hope to see it in the 'submissions' section soon. Very Happy

Author:  amz_best [ Sun Oct 19, 2014 5:45 pm ]
Post subject:  RE:Calculate angle between two points

Can you do a tutorial on how to make those bullets, explode?


: