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.

Dark GDK / Jumping with 3 different velocities

Author
Message
Neon Sheild
14
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 20th Dec 2010 04:30
Hey guys,

I'm making a 3D FPS game right now, and I'm trying to get the player character to jump. I got jumping to work in the Y direction very easily, but I can't figure out how to making jumping "account" for the other two directions, x and z (for example, running and then jumping. I remember from physics class that the x and y directions, when jumping/falling, are unrelated and do not affect each other. We never did z vectors, but I know that it's independent as well...).
I've browsed through the forums here, and all jumping advice has only been concerned with the y direction...any help will be great appreciated

Here is my jumping code so far, just to show you what I have done so far:



P.S. 40 is where the camera is on the ground. I know I do not account for landing on any other object other than the ground, but that is not a concern for me right now because I don't have many objects lol

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Dec 2010 13:52
I've found probably the easiest way to handle running and walking jumping code is to stick with your Y axis control but just simply carry on moving the camera forward as you would normally do whether running or walking. That way if you are using collision then the camera will then be reset to a position where it is safe. No need for handling X and Z movement with the camera pointing in a particular direction.
The same goes for strafe movement. Just turn the camera 90 degrees left or right, move it forward then rotate the camera back 90 degrees.

Warning! May contain Nuts!
Neon Sheild
14
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 20th Dec 2010 21:48
Thanks! That worked really well.
The only issue with this though is that if I'm jumping forward, and then look to the right, I now start moving to the right...is there any way to make it so irrelevant of where I'm looking, I will continue to move in the direction of my initial momentum?

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Dec 2010 01:49
I think the only way to get around that using the same coding technique is to hold the forward motion whilst jumping and have a temporary rotation left and right (turn object after the movement is done). When the object has landed just swap over the values for the rotation. An "if jumping" check can use temp values. When landed another "if landed" will then swap the vars over. Hope this helps.

Warning! May contain Nuts!
Neon Sheild
14
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 21st Dec 2010 02:02
hm...I think I see what you're saying, but I'm not 100% sure...when you say "temporary rotation left and right" do you mean to continuously turn the camera left and right repeatedly while in the air? How would that preserve my initial direction?

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Dec 2010 03:01
When in jump mode hold onto the original direction of the camera until you land and then change them over the "in air" turning.

// move camera and do usual jumping code
{ blah blah }

if (jumping)
// turn cam using temp val
else
// turn cam using orig val

if (landed)
origcam=tempval
if (jump_activated)
tempval=origval

using it similar to this allows the camera to continue moving forward whilst being able to turn in mid air. On landing the original camera turn is reactivated and set to the temp value.

If you haven't got it post your control code and I'll see what I can do for you.

Warning! May contain Nuts!
Neon Sheild
14
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 21st Dec 2010 07:29
I'm sorry, but I'm still honestly not seeing what you're saying.
This is what I have so far:


Thanks again for all your help

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Dec 2010 17:14 Edited at: 21st Dec 2010 17:17
I'm not sure if this little piece of code will help but it's a general camera control code I use for everything I do while I'm testing things out. I haven't implemented a jump in it yet but I have noticed you are using the parabola curve used in a lot of the old Speccy and Commodore 64 games years ago.


To use this in your program before your main loop use:

CamControl mycam; // will initialise a class for use
mycam.position(newxpos, newypos, newzpos); // set new position of camera

And then in your main loop just simply add the command:
mycam.update();
it will handle all movement, strafe and mouse controls.

I'm going to update this for you today to include a simple parabola jump function when either space or mouse key is pressed. I'll make it initialise the jump on the Y axis and return to where it jumped from while controlling movement in the fashion I've been trying to explain.

Warning! May contain Nuts!
Neon Sheild
14
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 23rd Dec 2010 04:39 Edited at: 23rd Dec 2010 04:40
After looking at your class and testing it out...it does pretty much what I did in the same way, just using slightly different values (e.g.
instead of
)

But what were you saying about temp and orig values?

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.

Login to post a reply

Server time is: 2024-09-28 14:05:07
Your offset time is: 2024-09-28 14:05:07