Streak Thunderstorm Posted May 26, 2009 Report Share Posted May 26, 2009 M'kay. I got a problem. I want to shoot an object based on the angle which Sonic is standing. I want the X and Y speeds to change to move along that angle. I also want to be able to charge it and make it move faster But still along that angle at which Sonic is standing. How do I does that? Link to comment Share on other sites More sharing options...
DimensionWarped Posted May 26, 2009 Report Share Posted May 26, 2009 Pictures please. I'm a little confused about the exact details of what you are asking, but I do know trajectory. Link to comment Share on other sites More sharing options...
Streak Thunderstorm Posted May 26, 2009 Author Report Share Posted May 26, 2009 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. Link to comment Share on other sites More sharing options...
cyborg_ar Posted May 26, 2009 Report Share Posted May 26, 2009 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 More sharing options...
Sockman Posted May 27, 2009 Report Share Posted May 27, 2009 I'll just post what I posted in a similar thread in the R&D boards. [qimg]http://img220.imageshack.us/img220/7271/sonicvectorqp8.png[/qimg]Hope that helps. Although this probably isn't helpful if Sonic isn't moving. Link to comment Share on other sites More sharing options...
Streak Thunderstorm Posted May 27, 2009 Author Report Share Posted May 27, 2009 Thx. Got it to work. Link to comment Share on other sites More sharing options...
Recommended Posts