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 Discussion / gravity in a first person shooter

Author
Message
gareth
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Dec 2002 23:14
okay i got my game, which is a first person shooter, and ive deleted the matrix and put an object in, how can i make it so this object is the floor, and when you move off it u fall to a lower floor, basiclly i wanna know how to make objects as the floor, and how to do gravity in a fps game? ive got collsion working well good tho
thanks
-gafy
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 17th Dec 2002 00:45
you must have a matrix for that

xxxpetratxxx
B. R. W
Rpg Cyco
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Australia
Posted: 17th Dec 2002 01:01
Yeah, it would be extremely hard to write gravity code for level object. It has been done, but I dunno how to do it myself.

l8ter

Rpg Cyco

http://rpgcyco.fsonline.ca
Specs: PIII - 866MHz, 120MB SDRAM, 8MB SiS 630, 17inch monitor, 18.6GB HDD 5400rpm, Win ME, DX8.1b, 56k Modem
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 17th Dec 2002 01:05
You don't need a matrix for that. You can find the y value of the upper side of the object (assuming it's flat) and do collision checks on that y value. Gravity I found hard to do, I think you have to explicitly check the collision with the floor every time to make sure the gravity works ok. Basically you have an acceleration due to gravity, and a y velocity that pulls the object downwards. You know how velocity and acceleration work, every cycle the acceleration is added to the velocity and the velocity is added to the position. As you fall through the air you fall faster and faster - the acceleration at work, but if you hit the floor then you stop falling, so you must include a routine that will set the y velocity to zero if you have collided with the floor. Then to include jumping, simply set the y velocity upwards on a keypress and gravity will take care of it.

#PSEUDOCODE - WILL NOT COMPILE#
acc=-5
do
yvel=yvel+acc
if collided with the floor then yvel=0
if jumpkey()=1 and collided with the floor then yvel=20
y=y+yvel
loop

Login to post a reply

Server time is: 2024-03-03 15:13:08
Your offset time is: 2024-03-03 15:13:08