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.

DarkBASIC Professional Discussion / How to add gravity

Author
Message
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 17th Feb 2014 00:57
So i am making this building game with blocks and i have made it so that you can walk over 1 block, but once you go on top of the block you cant come down. I have tried tons of things but they either make me fall through the floor or glitch horrifically with the camera. Here is the code:



The cubes that i place at the start or just for testing because i haven't figured out how to make you be able to place blocks in game. If anyone could help with that as well that would be appreciated. If you want to see the game in action just go here:


Builders Game

This has all the textures i'm using and stuff like that. If there is anything else i could improve upon let me know that would be greatly appreciated. Thanks in advance for any tips!

-FishCube-
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 20th Feb 2014 05:55
try something like
check for collision or intersect at a point below player
if there is no object then decrease player y position.

To Err is Human...
To Arr is Pirate!
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 20th Feb 2014 12:18
For a more realistic gravity effect, set up a variable for the player storing his y velocity. If there's no ground beneath him, increase this velocity by a small constant value, and then increase his y position by his y velocity. As soon as he collides with the ground, set the velocity back to 0. This way you could also easily add a jumping behaviour by just setting the velocity to a high negative value.

Login to post a reply

Server time is: 2026-07-06 07:51:27
Your offset time is: 2026-07-06 07:51:27