Jumping

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Melan
Posts: 9
Joined: Sun Sep 07, 2008 9:29 pm

Jumping

Post by Melan »

Hey!
i want to implement jumping in my ego shooter.
i tried it like that:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	bool OnEvent(const SEvent& event)
    {
		if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
        {
			switch (event.KeyInput.Key)
            {
				// Jump
				case KEY_SPACE: 
					 camera->setPosition(camera->getPosition() + vector3df(0, 400, 0));
					 return true;
it works, but the camera is suddenly at the new place(+400).
For jumping it would be better if it go not suddenly but slowly in the air and slowly back (this i made with gravitiy).
How can i make that i jump slowly up and not suddenly?
thx
drarem
Posts: 81
Joined: Mon Mar 06, 2006 4:40 am
Contact:

Post by drarem »

My thoughts for what they are worth :P

Make jump a 'state' feature of your code, like a bool flag. If this flag is set, call the jump function and increment/reach height/decrement your Y position. Let your x/z momentum carry you forwards (eg, don't touch them). when your Y value is back to 0 or you collided with ground, turn off the bool jump flag.
Melan
Posts: 9
Joined: Sun Sep 07, 2008 9:29 pm

Post by Melan »

do you have some code?
i mean if i make it first +20 then +20 then +20 because its slower then, the gravity makes it back to 0.
drarem
Posts: 81
Joined: Mon Mar 06, 2006 4:40 am
Contact:

Post by drarem »

If it was me I would call this jump loop inside the game code, paying attention to the affect it has on your game timer(s).

This is pseudocode, may have an error, but oldY, vheight, etc need to be global or at least within the scope of the main_loop().

Code: Select all

bool Is_jumping=0; // global

main_game_loop() {
..
while (Is_jumping)  jump_loop();
..
}

jump_loop() {
 oldY = node.Y;
 vheight = oldY + 20; // (jump 20 high)
 jumpup=1;
 if (jumpup==1) node.Y=node.Y - 1;
 if (node.Y >= vheight) && (jumpup) jumpup=2;
 if (jumpup==2) node.Y=node.Y + 1;
 if (oldY>=node.Y)  { Is_jumping=0; jumpup=0; }

}
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post by happilylazy »

Doesn't one of the basic tutorials (ones that come with irrLicht distro) have the jumping functionality implemented, if I recall correctly.
What now??? =_=''
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The FPS camera has basic jump functionality. 1.5 has an enhanced version, which could do with some testing.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

rogerborg wrote:The FPS camera has basic jump functionality
Can you tell me more about that basic jump functionality please?
After reading this sentence you will realize you have wasted 5 seconds of your life
Josh1billion
Posts: 125
Joined: Thu Dec 11, 2008 9:50 pm
Location: Wisconsin
Contact:

Post by Josh1billion »

The Onslaught wrote:
rogerborg wrote:The FPS camera has basic jump functionality
Can you tell me more about that basic jump functionality please?
All I know off-hand is that there is an argument in the addCameraSceneNodeFPS() function which asks for jumping power. I tried setting it myself once but it didn't seem to change anything.
www.JoshForde.com

Latest release: Super Orbulite World.
In development: Season of Dreams and others
Slippy
Posts: 13
Joined: Fri Dec 19, 2008 3:52 am

Post by Slippy »

Here's my FPS camera. It uses WASD for movement and SPACE for jumping.

Code: Select all

    // CREATE WASD KEYMAP ARRAY
    SKeyMap keyMapWASD[5];
    keyMapWASD[0].Action = EKA_MOVE_FORWARD;
    keyMapWASD[0].KeyCode = KEY_KEY_W;
    keyMapWASD[1].Action = EKA_MOVE_BACKWARD;
    keyMapWASD[1].KeyCode = KEY_KEY_S;
    keyMapWASD[2].Action = EKA_STRAFE_LEFT;
    keyMapWASD[2].KeyCode = KEY_KEY_A;
    keyMapWASD[3].Action = EKA_STRAFE_RIGHT;
    keyMapWASD[3].KeyCode = KEY_KEY_D;
    keyMapWASD[4].Action = EKA_JUMP_UP;
    keyMapWASD[4].KeyCode = KEY_SPACE;
    ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 100, 0.2, 0, keyMapWASD, 5, true, 3);
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

Slippy wrote:Here's my FPS camera. It uses WASD for movement and SPACE for jumping.

Code: Select all

    // CREATE WASD KEYMAP ARRAY
    SKeyMap keyMapWASD[5];
    keyMapWASD[0].Action = EKA_MOVE_FORWARD;
    keyMapWASD[0].KeyCode = KEY_KEY_W;
    keyMapWASD[1].Action = EKA_MOVE_BACKWARD;
    keyMapWASD[1].KeyCode = KEY_KEY_S;
    keyMapWASD[2].Action = EKA_STRAFE_LEFT;
    keyMapWASD[2].KeyCode = KEY_KEY_A;
    keyMapWASD[3].Action = EKA_STRAFE_RIGHT;
    keyMapWASD[3].KeyCode = KEY_KEY_D;
    keyMapWASD[4].Action = EKA_JUMP_UP;
    keyMapWASD[4].KeyCode = KEY_SPACE;
    ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 100, 0.2, 0, keyMapWASD, 5, true, 3);
Thanks man your code helped me a lot, I will repay you with this great song
After reading this sentence you will realize you have wasted 5 seconds of your life
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

By the way, I have a last question, when I jump, the camera doesn't return to its original position, do I have to set it manually or that's the part when a physics engine has to be used?
After reading this sentence you will realize you have wasted 5 seconds of your life
Slippy
Posts: 13
Joined: Fri Dec 19, 2008 3:52 am

Post by Slippy »

The Onslaught wrote:By the way, I have a last question, when I jump, the camera doesn't return to its original position, do I have to set it manually or that's the part when a physics engine has to be used?
Yes, you use the collision response animator on the camera as seen in tutorial 7 on the irrlicht website.
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

Ok, I've been checking tutorial number 7 and I have a question.

We have this piece of code

Code: Select all

scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* q3node = 0;
the thing is, they load the mesh, via a bsp file, I load the scene via an irr irr file (irrEdit), is there any extra step I need to do?, to get that mesh from the irr file (I hear its just an xml file)l).

Thanks in advance.
After reading this sentence you will realize you have wasted 5 seconds of your life
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

sorry, my bad I posted the question before reading the FAQ
After reading this sentence you will realize you have wasted 5 seconds of your life
Post Reply