Using sin and/or cos to jump
Author |
Message |
richcash
|
Posted: Wed Apr 19, 2006 3:53 pm Post subject: Using sin and/or cos to jump |
|
|
When making a mario-like game, I just use a bunch of 'if' statements to allow my character to jump properly. However, I think there is a more efficient way using sin or cos, but I don't know how. Can anyone tell me why and how to use sin or cos for this? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
do_pete
|
Posted: Wed Apr 19, 2006 4:04 pm Post subject: (No subject) |
|
|
You don't need that, all you need is a y-velocity variable and add it to your y variable. |
|
|
|
|
|
richcash
|
Posted: Wed Apr 19, 2006 4:10 pm Post subject: (No subject) |
|
|
Yes, that is the way I always do it but I heard the better way is to use some sort of formula with sin or cos in it. |
|
|
|
|
|
iker
|
Posted: Wed Apr 19, 2006 6:18 pm Post subject: (No subject) |
|
|
It may come in handy to use sin and cos, or even tan (most likely tan) when your running and jumping. tan theta (or the angle that you would be jumping at) = yVelocity / xVelocity. Since tan = sin/cos (Not 100% sure, damn trig identities) then the equation to find the angle would be
sin theta / cos theta = yVelocity / xVelocity
So realy, sin and cos would only be good when needing to find an angle, or if an angle of jumping is already found, to see how much force would be put into the verticle thrust of the jump. |
|
|
|
|
|
MysticVegeta
|
Posted: Wed Apr 19, 2006 7:09 pm Post subject: (No subject) |
|
|
also, changing the y would only make the character go up and down but it would be more appealing to use trig to make them jump a more smooter quadratic-like curve |
|
|
|
|
|
codemage
|
Posted: Thu Apr 20, 2006 8:55 am Post subject: (No subject) |
|
|
Unless the character is jumping really slowly, the user won't be able to notice the difference.
Jumps are taking place over only a few frames (the refresh rate of turing is quite slow). That's not enough points to visibly distinguish an actual parabolic arch from one that's approximated. |
|
|
|
|
|
zylum
|
Posted: Thu Apr 20, 2006 4:22 pm Post subject: (No subject) |
|
|
guys, you dont need trig for jumping... when you take physics, you will learn that projectiles have a constant x velocity (air is negligible) and that the y velocity is affected by gravity (an acceleration in the y direction). so therefore you can handle everything in components like so:
code: | var x, y, vx, vy, ay : real
x := 100
y := 10
vx := 2
vy := 5
ay := -0.05
loop
x += vx
y += vy
vy += ay
drawfilloval (round (x), round (y), 10, 10, black)
delay (10)
end loop |
notice how it makes a parabolic shape. so when your player jumps, just set his y velocity to whatever (higher to make him jump higher). |
|
|
|
|
|
|
|