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 / making an object jump and having gravity

Author
Message
oblivion 2
22
Years of Service
User Offline
Joined: 5th Nov 2003
Location:
Posted: 5th Nov 2003 19:43
how am i able to make a model jump and then go down again by gravity? i've been trying this for weeks i still haven't figured it out
Inkybro
23
Years of Service
User Offline
Joined: 31st Dec 2002
Location: Where I live :)
Posted: 5th Nov 2003 20:01
Lots of math. I'm not that advanced but I really hate it when people are clueless about what to do (I am, but I know it is physics). Anyway, if I was working on an FPS at the time I could easily figure it out.

Sorry just thought I'd share my thoughts as like EVERYONE asks this question the same. They never say how much they know about physics/math, how much they have done, etc.

No offense of course

Inkybro
23
Years of Service
User Offline
Joined: 31st Dec 2002
Location: Where I live :)
Posted: 5th Nov 2003 20:02
Oh, good luck too The good people here are bound to help ya

oblivion 2
22
Years of Service
User Offline
Joined: 5th Nov 2003
Location:
Posted: 5th Nov 2003 20:12
oke i tryed this

grav=-2
do
a=a+1
if spacekey()=1 then move object 1,a : jump=1
if a=200 then a=200
if jump=1 amd a=200 then move object 1,grav
loop

and this doesn't seem to work
will ya help me now, please?
oblivion 2
22
Years of Service
User Offline
Joined: 5th Nov 2003
Location:
Posted: 5th Nov 2003 20:13
oh i made one mistake that grav=-2 must be grav=grav-2 and must be placed under do
oblivion 2
22
Years of Service
User Offline
Joined: 5th Nov 2003
Location:
Posted: 5th Nov 2003 20:43
can you helpme out, please?
adr
23
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 5th Nov 2003 21:36
Keep in mind that move object moves an object relative to it's current position, as well as where it's facing. That means you'll need to use the free flight commands, like turn object left, before using move object. Personally, I don't think that's the right approach. Instead, keep tabs on your player's position and affect it like so (just 2 dimensions for the moment for simplicity's sake)...



This should show you the basic method for implementing jumping/gravity.

Can I ask you a Question?
What is it?
It's an interrogative form of sentence, used to test knowledge. But that's not important right now.
BHoltzman
23
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 5th Nov 2003 21:56
You're using a linear progression in your series. Gravity effects an object in more of a quadratic progression. So try something with a a^2 in it.
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Nov 2003 22:07 Edited at: 5th Nov 2003 22:08
in my fps tests using BSP worlds, the ground collision is handled for me, the gravity is just a simple piece of code trying to constantly move the player object downward each time thru the main game loop, but the collision cancels it out. if there is a ledge or something that the player can step off of the gravity then pulls down on the player until it reaches another "floor/ground" surface, then the player stops. You may want to replicate the same thing in your code and use your collision to stop the player moving downward, whether you are using bsp or not.
As far as jumping< I incorporated a simple jump routine but it is using a for-next and doesn't take into account any prior movement (ie running forward and pressing jump) so when I jump all perpendicular movement ceases while the player "jumps up" but when gravity takes over after the loop ends I can then continue to move the player forw/bkwrd/sideways as he is descending. this is because the gravity and the other movements are part of the main loop - I just haven't had time to fix the "Up" part yet.

Hopefully this gives you some ideas to work with
just my two cents

-RUST-
zircher
23
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 6th Nov 2003 02:12 Edited at: 6th Nov 2003 02:21
side note:

if a=200 then a=200

Is completely useless. I think you meant...

if a>200 then a=200
--
TAZ

PS. "can you helpme out, please?" This is about an hour after your first post and 30 minutes after your previous post. GET A CLUE. This is a fourm that people visit 24/7 from a dozen different time zones. A more reasonable time to wait is one day.

Programming is 90% patience and diligence, you have to read, read, and read again as well as test code fragments and walk through code examples. You own brain is your best resource. You won't learn as much if you're spoon fed everything.
Beta 1
22
Years of Service
User Offline
Joined: 27th Aug 2003
Location:
Posted: 6th Nov 2003 13:09
OK I think I should just have this post somewhere that I can copy and paste from to speed up answering the same question every few days.

If your object position is in stored in X,Y and Z variables the amount of gravoty you want is stored as variable G and the current speed of your object in each direction as VX VY VZ then each loop you must

calculate the force acting on the object (in this case just gravity and sum the forces in each direction to give acceleration

AX=(sum of all X forces)
AY=(sum of all Y forces)-G
AZ=(sum of all Z forces)

INC VX,AX
INC VY,AY
INC VZ,AZ

INC X,VX
INC Y,VY
INC Z,VZ

POSITION OBJECT N,X,Y,Z

This gives you "real" gravity where the object accerates as it falls rather than falling at a constant rate.

All variables need to be FLOATS or it is likley to not work.
There is no terminal velocity in this system if you want something to limit speed you will need to add a drag force into the equations.

Also there is no collision detection so you will go straight through the floor.

A simpler but less real method is to simply subtract G from Y every loop. This will make you fall a constant speed instead.
Black Hydra
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 6th Nov 2003 22:16
Go to binary moons tutorials they give a great example for how to use gravity. With a bit of effort you can splice it into your game.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th Nov 2003 01:59
Hi Oblivion,

I have attached some code which will hopefully help you.

Login to post a reply

Server time is: 2026-07-26 15:30:57
Your offset time is: 2026-07-26 15:30:57