Computer Science Canada help with trajectories |
Author: | zuber [ Thu May 31, 2007 8:12 am ] | ||
Post subject: | help with trajectories | ||
I did a search and came across these equations for making a bullet follow a proper path when launched: dy= viy * t + 0.5gt^2 viy = intial vertical velocity g = gravity (normally -9.8) dy = distance travelled verticall (or vertical position at time) t = current time dx=vix * t vix = intial horizontal velocity dx = current horizontal position t = current time Use SOH CAH TOA To Get viy, and vix vix = cos(angle) * power viy = sin(angle) * power I translated that into the following java code:(that runs through a while loop, t gets reset to 1 before the loop's execution)
as the angle gets adjusted,(from its initial value of 45) the ball flies off in a seemingly random direction. Can anyone tell me what I'm doing wrong? (Oh and I tried using acos/asin, but the projectile get's stuck in the bottom left corner of the screen when I do so) |
Author: | McKenzie [ Sat Jun 02, 2007 7:18 am ] |
Post subject: | Re: help with trajectories |
Math.sin() and Math.cos() deal in Radians. Odds are you are keeping your angle as degrees (PI radians == 180 degrees.) Also, may I suggest you keep all of your values as double and only cast as int when you draw, this will avoid unnecessary round-off. |