Computer Science Canada Make a Char Jump |
Author: | MiX-MaztA-M8riX [ 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
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! |
Author: | Tony [ Thu Jan 19, 2006 10:56 pm ] | ||
Post 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.
where maxHeight is the maximum height your character will reach and time is the duration spend in the air |
Author: | codemage [ Fri Jan 20, 2006 10:33 am ] |
Post 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 |
Author: | MiX-MaztA-M8riX [ Fri Jan 20, 2006 2:26 pm ] |
Post 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. |
Author: | Drakain Zeil [ Fri Jan 20, 2006 4:33 pm ] |
Post 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" |
Author: | Cervantes [ Fri Jan 20, 2006 4:56 pm ] |
Post subject: | |
There's a lot of code in this jumping thread that you will probably find useful. |
Author: | MiX-MaztA-M8riX [ Fri Jan 20, 2006 5:27 pm ] |
Post subject: | |
Thanks for the info!, and for the Link Cervantes! Oh, and btw, thats the best Avatar ever ![]() Rock On The Penny! ![]() |
Author: | MiX-MaztA-M8riX [ Fri Jan 20, 2006 9:49 pm ] |
Post 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! |
Author: | Cervantes [ Sat Jan 21, 2006 10:54 am ] |
Post 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. |
Author: | MiX-MaztA-M8riX [ Sat Jan 21, 2006 3:42 pm ] | ||
Post subject: | |||
Something like that, cuz it doesnt seem to work? O_o |
Author: | Tony [ Sat Jan 21, 2006 10:02 pm ] |
Post subject: | |
Quote: for i : 1 .. 20 y += Grav end for you're going nowhere but up from there ![]() ![]() you need a variable for vertical acceleration. When your character jumps, vertical acceleration is set to the power it jumps with, each time through the loop gravity is added to acceleration variable, so if gravity is 10 and power is 20, it will take gravity 2 steps to catch up and start pulling you down: step | v_acc | height -----+--------+-------- 0 20 0 // jump from the ground 1 10 20 2 0 30 // 3 -10 30 // top of the arch 4 -20 20 5 -30 0 // back on the ground |