Make a Char Jump
Author |
Message |
MiX-MaztA-M8riX
|
Posted: Thu Jan 19, 2006 10:47 pm Post subject: Make a Char Jump |
|
|
Hey, sorry for the slew of posts, but I'm in a real time crunch with the whole Final Project thing.
ok, so I'm doing a side scroller type project, and I want to make my jump a lot more than just
code: |
for iy : y .. y+50
Draw.FillBox (x,iy,x+15,iy,255)
end for
for decreasing iy : y + 50 .. y
Draw.FillBox (x,iy,x+15,iy,255)
end for
|
Chances are that doesnt even work, but you get my point. I'm trying to figure out a way to make it more, mathematically calculated. The only catch is I have no idea how to use angles in turing, if anyone out there can explain how to jump normally instead of crappy diagonals all the time. They look horrible, and I want to avoid them at all costs. So please, any help would be greatly appreciated.
Cheers! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Jan 19, 2006 10:56 pm Post subject: (No subject) |
|
|
Forces! Vertical acceleration upwards from the jump against vertical acceleration downwards due to gravity.
Though in essance you end up with a -(x^2) type of graph.
code: |
-(x^2 - (time/2) ) + maxHeight
|
where maxHeight is the maximum height your character will reach and time is the duration spend in the air |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
Posted: Fri Jan 20, 2006 10:33 am Post subject: (No subject) |
|
|
You probably won't be able to do it with for loops.
In your main loop
when you jump,
- disable jumping
- add a specefied height to your y location
then keep adding that value (minus gravity)
eventually that value will become negative (since you're subtracting gravity from it each time)
....even more eventually, your character will hit the ground, at which point
- you stop adding the height variable to your character
- you re-enable the jump key |
|
|
|
|
![](images/spacer.gif) |
MiX-MaztA-M8riX
|
Posted: Fri Jan 20, 2006 2:26 pm Post subject: (No subject) |
|
|
Hey Tony, I'm not sure if that was supposed to make complete sence or not, but I'm not sure I'm getting that. Also, what's with the use of time? I'm not too firmiliar with it. |
|
|
|
|
![](images/spacer.gif) |
Drakain Zeil
|
Posted: Fri Jan 20, 2006 4:33 pm Post subject: (No subject) |
|
|
There's all sorts of things you can do for gravity. Also, I posted a tutorial on angles just yesterday.
So, for example, you could increment a dot by a value of:
increment value by (Distance(A,B))
But that will move A slower towards B, so, instead, try something like inverting that:
decrement value by (Distance (A,C))
Where C would be a point opposite to that value, perhaps some where up in the sky. This would make objects get slower as they go towards the sky, and speed up as they go back down again.
Also, for true physics, you can use the d=v*t formula (distance, speed, time), and change the V value as acceleration dictates, t as time goes on, and d just becomes the product of the two, so use that value to change distance.
Btw. Gravity acceleration is on average 9.8 m/s on earth, which doesn't mean much on your screen unless you have something you can relate to a meter. (And again, if you don't, just use that first thing I said)
Actually... now that I think about it... years ago I made a pong game in flash, and the paddles got slower as they closed in on the mouse position, what I did for that is:
Get closer to the pointer, by subtracting (pointer - paddel), then divide that distance by 5, to make a nice "speed gradient" |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Fri Jan 20, 2006 4:56 pm Post subject: (No subject) |
|
|
There's a lot of code in this jumping thread that you will probably find useful. |
|
|
|
|
![](images/spacer.gif) |
MiX-MaztA-M8riX
|
Posted: Fri Jan 20, 2006 5:27 pm Post subject: (No subject) |
|
|
Thanks for the info!, and for the Link Cervantes! Oh, and btw, thats the best Avatar ever
Rock On The Penny! ![Laughing Laughing](images/smiles/icon_lol.gif) |
|
|
|
|
![](images/spacer.gif) |
MiX-MaztA-M8riX
|
Posted: Fri Jan 20, 2006 9:49 pm Post subject: (No subject) |
|
|
Ok, more troubles! I followed some of your help (what I understood) but I can't seem to get my dude to sotp, you can 'fly' just by holding the jump button. So is there a way to disable the input of a button (or something along the lines of that) until he lands? cheers! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Jan 21, 2006 10:54 am Post subject: (No subject) |
|
|
Only allow the object to jump if there is some ground below him. You'll need to do some collision detection to determine if he's on the ground. |
|
|
|
|
![](images/spacer.gif) |
MiX-MaztA-M8riX
|
Posted: Sat Jan 21, 2006 3:42 pm Post subject: (No subject) |
|
|
code: |
process Jump
if jump = true and whatdotcolor (round (x), round (y - 2)) not= 255
then
for i : 1 .. 20
y += Grav
end for
jump := false
end if
end Jump
|
Something like that, cuz it doesnt seem to work? O_o |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
|
|