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 / Gravity problems

Author
Message
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 03:44
I'm finding the implementation of gravity quite difficult in my program. I thought I was doing good to have the ball following a matrix! What a sheltered thought that was...I need some start for gravity (maybe just a mathematical explanation) just some direction. I tried a few examples here and there, changing my Y value, but i want smooth transitions from going up, to going down ... and sometimes the camera (which is "inside" the player in 1st person, and I also have a 3rd person option) would just get stuck in one place ... ARGHHH. Any general help would be most appreciated, thanks!
P.S. This is what the alphabet would look like if Q and R were eliminated.
Zach
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 28th Feb 2003 04:30
You need to set you're y value with matrix hieght()
I think thats right but its been a while..

Tupelo, Ms
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 05:00
I know that, I already have that (player following matrix hills) but it does a lick off beans (yes, i'm Southern) for jumping and falling. But thanks, keep em coming!

P.S. This is what the alphabet would look like if Q and R were eliminated.
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 28th Feb 2003 18:47
For jumping and the like you'll need a variable for your y velocity. All gravity is is an acceleration downwards on the object. You remember the laws of motion, distance = speed x time and speed = acceleration x time. To start off I usually choose the positive velocity as upwards. This means to apply gravity, I need to decrease the velocity upwards every cycle, so just take a constant value off the y velocity every loop. When the object hits the ground, you want to stop it, so set the y velocity to 0 every time, to stop the gravity having an effect. Here's some code:



You can change some of the values to see what effect they have. Using this method it is better not to set the height to that of the matrix, but instead see what the difference between the heights you are travelling is, and then set the upward velocity of the object appropriately, but only if it is positive. This would allow you to move up a big slope, meaning you need a high y velocity. When you reach the top, the velocity should be negative to move it along the terrain, but you don't set a negative velocity, you let graviy do its work. If you need any of that explaining just ask.

Once I was but the learner,
now, I am the Master.
BoB Vila
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United States
Posted: 28th Feb 2003 19:06
I do a lot of cheezy coding but it works. I made a jump routine just for testing it.

All I did was make a value called jump, it would either be
0,1 or 2. 0 - not jumping, 1 - on the way up 2 - on the way down.

If jump becomes 1, it starts incrementing your height above the matrix until its equal to or greator than the max jump distance. then jump becomes 2 and it subtracts in increments until you back on the matrix.

which is very simple, but doesn't look quite right because realistically you will begin to slow down as you reach the pinicle height, and slowly speed up on the way down. So what I did was add another IF statement that would adjust the increment counter based on how close it was to the max jump.

I'm not some great math wizard so I don't work anything out in my head, I just keep playing with the numbers until it looks right. from there you can do all sorts of things like add a speed variable that gets added to your max jump and also effects the increment value for the jump.
Little tweaking here, and a little tweaking there.. walla..

I hope that sounded right, and hey if I'm doing it the "normal way". Then excuse me I don't really know how its normally done, thats just what I came up with yesterday. (I just got DBP and this sort of thing)
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 19:37
That code works, to some extent. When I press spacekey() because i've wedged the code into my existing, it automatically repositions the "player" to the yvel, instead of sending it up smoothly...but still a step ahead of where i was before! Thanks, and if there is any way I can assign a Cosine value to the Y#? (I don't remember much from Trig, but I do know that it would constantly rise and file) I may have to use the same equations (somewhat) for my projectiles, like archers arrow.

P.S. This is what the alphabet would look like if Q and R were eliminated.
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 28th Feb 2003 22:38
I suppose you could use y#=sin(x#) from x#=0 to 180, but you would need some coefficients in there to get it to travel properly. These would have to be worked out beforehand, and also it would be more difficult to alter the object's motion while in the air.

Have you run the code on its own to see how it should work? The only way the player could be repositioned to the yvel# would be if you were using the yvel# as the y# value, this should be very easy to avoid...

Once I was but the learner,
now, I am the Master.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 22:47
Hmm, I did try the code you gave me, and as far as jumping, it jumped alright, but it was instantaneous...I'll try it again though, because I can't see why it's not working as it should.

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 22:51
Could it be that I accidentally forgot to delete my old Y# value! ... could be, let me try it.

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 22:58
Hmmm, still happens too fast, i'll try to switch some things around, and see how that works, and keep you posted...literaly. Thanks for all the help so far though!

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 28th Feb 2003 23:39
Woah, ok, you code works fine alone, that's what I want. And I tried to adapt it to my own code, but for some reason it just moves the ball quickly ... maybe i'm missing something.

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 1st Mar 2003 00:34
Explain that part about setting Y# to the height of the matrix... can I still use position object 10, X#, Y#+get ground height(blah), Z#? or is there some other way?

P.S. This is what the alphabet would look like if Q and R were eliminated.
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 1st Mar 2003 02:13
Try this ..maybe with some adaptation it will work for you

Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 1st Mar 2003 02:17
Or this..same concept on a matrix
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 1st Mar 2003 04:50
Thank you, I'll try those, but let me post my code so far ...



Sorry if it's confusing, I don't do nearly as much commenting as i should. I was only trying to add the gravity to one camera, then duplicate success with the other ... but it's not working well at all. Thanks guys.

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 1st Mar 2003 09:45
I got it to work! Now, only one TINY problem ... really! Whenever i'm going down-hill, i bounce. Fixes, anyone?

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 1st Mar 2003 09:46
P.S. Using the Darthsters code in my main loop ... Thank you SO MUCH, I NEVER could've done it without ya'lls help.

P.S. This is what the alphabet would look like if Q and R were eliminated.
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 1st Mar 2003 22:23
My code includes a bit of bouncing, but I've noticed that problem when going down hills. It's caused by the y velocity being set to zero, because the object is on the ground, but then moving so the object is above ground (above the downhill bit). This means whenever it hits the ground it loses it's y velocity and moves horizontally, in effect bouncing. You can fix this by not going downhill so fast, or doing some collision to see if you are going to hit the ground under the effect of gravity next time. Or, just moving the object horizontally (x and z) and then doing the checks for gravity. Hmm...

Once I was but the learner,
now, I am the Master.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 2nd Mar 2003 02:52
Hmmm, I have the new and old height values stored, but i'm not quite clear on how to use them.

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 2nd Mar 2003 02:55
Or how do I stop the bouncing? (probably don't need it) bodies don't bounce )

P.S. This is what the alphabet would look like if Q and R were eliminated.
TogaMario
21
Years of Service
User Offline
Joined: 30th Jan 2003
Location:
Posted: 2nd Mar 2003 03:59
I FIXED IT! Yay! I changed setting yvel=0 to vyel=-1 ... works like a dang charm ... THANK YOU THANK YOU THANK YOU! Beers for everyone! Not really ... but you're going in the credits darn it.

P.S. This is what the alphabet would look like if Q and R were eliminated.

Login to post a reply

Server time is: 2024-09-19 22:43:40
Your offset time is: 2024-09-19 22:43:40