Data Realms Fan Forums http://45.55.195.193/ |
|
Bullet curving http://45.55.195.193/viewtopic.php?f=73&t=15943 |
Page 1 of 1 |
Author: | Mind [ Mon Jul 20, 2009 11:29 pm ] |
Post subject: | Bullet curving |
Yeah. So... I have a bullet that travels randomly, and I want it to go towards actors when it gets close enough. The code "self.Vel = actor.Pos - self.Pos" makes the bullet head directly towards the target in a straight line. However, I wanted it to keep it's current path and gradually curve towards the target, like this: Any help would be much appreciated |
Author: | LowestFormOfWit [ Mon Jul 20, 2009 11:50 pm ] |
Post subject: | Re: Bullet curving |
Use a sine wave. |
Author: | Mind [ Mon Jul 20, 2009 11:51 pm ] |
Post subject: | Re: Bullet curving |
Yeah I wish I knew how :3 |
Author: | LowestFormOfWit [ Mon Jul 20, 2009 11:52 pm ] |
Post subject: | Re: Bullet curving |
Mind wrote: Yeah I wish I knew how :3 Me too! Just ask one of the Sparkle Mages. |
Author: | CrazyMLC [ Tue Jul 21, 2009 12:02 am ] |
Post subject: | Re: Bullet curving |
LowestFormOfWit wrote: Mind wrote: Yeah I wish I knew how :3 Me too! Just ask one of the Sparkle Mages. A new term has been created today. |
Author: | Kyred [ Tue Jul 21, 2009 1:39 am ] |
Post subject: | Re: Bullet curving |
Lol! This post has good timing. About an hour ago, I got a projectile to move along the path of a desired function in CC using only velocity. If you add (or subtract) the target's velocity into the equation, it should account for moving targets. The way I did it was I took the trajectory that I wanted the projectile to follow and turned it into a parametric function (where both the positions of x and y are based on a function of time) that is based on the distance and angle of your projectile to the target. Then you take the derivative (rate of change) of those functions with respect to time to get the function for velocity that you need to make the projectile travel along that path. I'll be posting another proof of concept some time in the week or so that will explain how to do something like this. |
Author: | BlackNecro [ Tue Jul 21, 2009 2:37 am ] |
Post subject: | Re: Bullet curving |
I'd prolly go about something like: Code: self.Vel = self.Vel + (actor.Pos - self.Pos) * x * dt x being the time in seconds to reach the desired direction, dt being the simtime of a timer resetting after each refresh. Either that works or ... not as I'm pretty much tired :3 Or incase you wanna use a sine wave lemme think for a bit. |
Author: | TheBigCheese [ Mon Jul 27, 2009 10:11 pm ] |
Post subject: | Re: Bullet curving |
Could you base the sine function on the distance to the target? That would make it end up at 0 on the normalized y axis relative to the normal bullet path, assuming you stretched the sine function correctly. The actual bullet placement would then be the bullet's relative y axis projected into the screen's coordinates. To get a random curve you would just multiply the sine by a random number -1 through 1 which would flip it and squish it depending on the number. |
Author: | Kyred [ Sun Aug 02, 2009 7:03 pm ] |
Post subject: | Re: Bullet curving |
If anyone is still interested in this, here are the equations: For position: Code: t = time (time in milliseconds / 1000); tmax = total time for the projectile to follow the curve. theta = angle from Vector(1,0). (ie. projectile.Vel.AbsRadAngle) a = relative amplitude of the wave. x = t/tan(theta) y = tan(theta)*t + a*sin(2*(t*PI)/tmax) If you want to do it using velocity, then just take the derivative with respect to time and you get: Code: t = time (time in milliseconds / 1000); tmax = total time for the projectile to follow the curve. theta = angle from Vector(1,0). (ie. projectile.Vel.AbsRadAngle) a = relative amplitude of the wave. x = 1/tan(theta) y = tan(theta) + a * (2*PI)/tmax * cos( 2 * (t*PI)/tmax) |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |