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 / another matrix question: jumping

Author
Message
gamer3999
17
Years of Service
User Offline
Joined: 28th Oct 2007
Location:
Posted: 29th Oct 2007 19:56
How would I have an object jump on a randomized matrix?
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Oct 2007 01:58 Edited at: 30th Oct 2007 02:17
OK this is just a quick programme because I'm not very at home with 3D and as far as I can remember I haven't tried jumping before, but what I thought was something along these lines:



playerheight#=1.2
jumpheight#=0.7


The first variable is the height you want the player to be off the ground. I made the little sphere float above the ground by a fair way. The second is the height of the jump - obviously, the higher you want him to jump, the higher you set the value.

if jumping=1
Check if your character is jumping

inc jumpvar,6
If he is, then increase the progress through the jump. The value can be changed at the end, but I would use factors of 360 to get a smoother jump (1,2,3,4,5,6... hey actually that's quite a versatile number)

else : jumpvar=0
If your character isn't jumping then reset the jumpvar variable

if jumpvar>180 then jumping=0
Make sure that when the jump actually finishes, the programme recognises this.

y#=groundy#+playerheight#+(jumping*SIN(jumpvar))
This is the actual jump.
The groundy# was the variable of the ground height at this point. This is added to the basse height you want the player off the ground. Then finally you add the jumping variable. The "jumping" is there so that if your character isn't jumping then that term will equal 0, therefore be ignored.

The "jumpvar" is a number between 0 and 180. You take the sine value of this, as between the values of 0 and 180 degrees, the sine graph looks is a curve from 0 to 1 and back again (look it up on the internet if you're not familiar with it). Therefore, your character will jump upwards, then when he reaches the peak of the jump start to fall again.

EDIT: By the way, this worked when I tested, but if it doesn't then sorry, I'm a bit tired and a little drunk and it's my first time trying to figure this out.

demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 2nd Nov 2007 05:43
... did this work?

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 2nd Nov 2007 13:28
There's no reason it shouldn't. The code looks fine.

STOP reading my signature!

Login to post a reply

Server time is: 2025-05-31 21:08:41
Your offset time is: 2025-05-31 21:08:41