Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Angle based trajectory


Recommended Posts

Ok, here it is. Sonic has an attack where he can charge up and shoot an object along the ground. See how he's on an angle? I want the speed to be based on the amount of charge done but I want it to move along the angle that he is on. It doesn't always have to follow the angle. It just has to take the initial angle and start movement.

post-33-138639763533_thumb.png

Link to comment
Share on other sites

note: since i don't know where will you implement it my example will be generic python (which should be possible to translate easily)

ok, to start the movement, set the bullet's speed to something along sonic's orientation vector (in this example i'll take it from his angle, but if your engine uses rotation matrices, you can get it from there)

bullet_speed[0] = cos(sonic_angle) * BULLET_STRENGTH
bullet_speed[1] = sin(sonic_angle) * BULLET_STRENGTH

Then, if your engine doesn't have a physics engine we are gonna do this calculation every frame (basic newtonian physics):

#TIMESTEP being the amount of time from frame to frame, at 50 fps its 1/50th of second = 0.02
bullet_position[0] += bullet_speed[0] * TIMESTEP 
bullet_position[1] += bullet_speed[1] * TIMESTEP
# acceleration of gravity
bullet_speed[1] -= 9.8 * TIMESTEP 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...