Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / collision, jumping, gravity, ect.

Author
Message
A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 25th Apr 2007 20:44
i need help with my side scroller game. i cant figure out my collision, gravity, and jumping. help im realy confused.

here is the code



remember im a beginner and just started this month so i probably make some stupid error.

plz help

what?
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 25th Apr 2007 23:41
i don't see anything wit da code, but i can't look at teh game 'cause i don't have teh media

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 26th Apr 2007 19:00
here's the game with no media, i got rid of the start screen


that help?

what?
A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 26th Apr 2007 19:06
here's the game with no media, i got rid of the start screen


that help?

what?
A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 26th Apr 2007 20:06
Ok...... so i see what i did wrong with the collision, mixed up the
variables. here is the new code


but i still need help with jumping and gravity.
plz help

(by the way, sorry for double posting

what?
Lucy
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Roanoke, VA USA
Posted: 27th Apr 2007 16:15
Well, gravity can be done by defining an amount that stuff should fall every frame, then go and set them to fall... like put in the loop to move them down by so much. Once you have collision in, they'll automatically stop on the ground and other things set to collide with so they won't fall through.

Jumping can be done in much the same way. You just need to know where they're going to be jumping and set them to raise up instead of jump. Then keep an accumulator that checks to make sure that the amount of height they've jumped isn't over certain amount. If it is, then stop making them raise up.

No matter where you are... everyone is always connected.
A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 27th Apr 2007 18:51
i under stand what your saying, but i already made the gravity and jumping, and i don't know whats wrong with the code. but thanks for the information.

what?
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 27th Apr 2007 18:55 Edited at: 27th Apr 2007 19:11
Create a gravity variable, a gravity rate variable, a jump speed variable, and a jumping variable.

Set gravity rate to the rate gravity increases by per loop. Set jump speed to the initial speed the user jumps at.

If the user isnt on the ground (get this data with your collision routine), move them down by gravity, then increase gravity by gravity rate.

If the user is on the ground, reset gravity to 0, and jumping to 0.

When the user presses the jumpkey, check if jumping = 1, if it does, dont do anything, if it doesnt, then they must be on the ground, in which case, set gravity to jump speed. Assuming jump speed is a negative value, the user will move upwards, slowing in speed until they begin to fall back down again, accelerating in speed.

To determine if an object is standing on a surface, use raycasting (the INTERSECT OBJECT command). Set the starting xyz position of the ray to the player's position, and the ending xyz to the player's x and z position, with a largely negative y value, checking for intersection with any map object. This will cast a ray directly below the user, and tell you the distance the user is to the closest polygon below them. If the distance is less than or equal to half the user's y scale, then their feet are on the ground, if not, they're airborn.

Raycasting should be used for collision as well, for better results, and assurance that a collision will be detected no matter what speed the user moves at, but thats another story.

All of the methods above have been explained in huge detail dozens of times in dozens of threads, do a search and you'll find what you need.

<edit>

Heres a demo program, it should work, havent tested it though;



A Tea Spoon
17
Years of Service
User Offline
Joined: 23rd Apr 2007
Location: good ol USA!
Posted: 27th Apr 2007 19:04
Wow thanks Ruccus! that fixed a few things with my game.
thanks for the help! i really appreciate it!

what?

Login to post a reply

Server time is: 2024-09-25 21:20:18
Your offset time is: 2024-09-25 21:20:18