views:

212

answers:

2

I need the algorithm to animate the arrow based on 2 parameters, angle while shooting and power while drawing the bow. Ive tried to use y=asinx but it works only when shooting in up direction. Doesnt work well while shooting with straight or down direction. Thanks.

+6  A: 

You could try simulating the motion instead of deriving the analytic function. i.e. keep track of the current position, velocity and acceleration vectors for the arrow, and each time-increment, update the position based on the velocity and the velocity based on the acceleration.

otherwise, if you need an analytic function, See @bnaul's answer for the analytic version

Jimmy
Simulating the motion would require extra logic compare to using function. Could you describe what is x, y, a, b, c here?
Ricky
Why use a slow and inaccurate brute-force solution to a trivially-solvable analytic equation?
Rex Kerr
@Rex: because the usual game-related case involves non-analytic components -- collisions with arbitrary terrain shapes or objects, for example.
Jimmy
@Jimmy: Intersection of a quadratic flight path with a triangle in the terrain is also easily analytically solved (i.e. use the quadratic formula). You still might want to do time stepping, but then you take steps along the analytic solution.
Rex Kerr
+1 for correct answer. This is how it's done in actual games. If the world is in any way complex - for instance, you have to hit a moving target, or one of non-trivial shape - this is far *far* simpler than using equations of motion.
BlueRaja - Danny Pflughoeft
+9  A: 

The flight of your projectile is described by

x(t) = v * cos(theta) * t
y(t) = v * sin(theta) * t - 1/2 * g * t^2

where t is time, v the initial velocity (power), theta the angle, g the acceleration due to gravity (e.g. 9.8 m/s^2), x the horizontal coordinate and y the height.

bnaul
Assuming no wind and negligible air resistance
Tim Goodman
Thanks ill try this and will update if it works for me or not. Thanks
Ricky
And neglecting coriolis force ;-)
Steve Jessop
And neglecting bufferflies :)
Jimmy
Power = how hard you can pull the bow back, stored energy, or velocity, I wonder? The first two are proportional to v^2, not v.
Rex Kerr