[SOLVED] Jumping/Impulse with momentum using nodes

I believe that this setup does what you’re after:
image

It essentially moves the character (cube) left/right using the left right keys, and makes them jump using space. If they jump, they retain their horizontal momentum, but the contact node makes sure that they can only change their momentum (either horizontal or vertical jumping) when in contact with the ground.

Note, the shortcoming of this is that it only checks for one ground object, so if the cube is say, on top of another object, then they’re unable to move/jump.

This would be fixed by replacing the contact node with a node group which actually detects if any object in a specific collision group is below the cube.

Thanks, what are the drop-down values on those three “Impulse” headings?

I don’t think this will read the jump though if another button is down, it’s a similar setup to what I have (but my velocity vectors are relative to the direction of the camera/player)

do it like this. when player press w then make a bool and assign true to it that is check if player is moving?
then check if player is pressing space and use branch there, in bool value use the if player is moving value. in true then apply impulse with linear velocity and if false then just apply impulse.

Hope this help.

1 Like

.3 for left and right, and 4 for jump. You may need to adjust these based on the scale / mass of the objects in your scene.

I’ve got it a little different due to the camera and turning mechanism but it does seem to let me press jump and the move button at the same time, is that simply because the “Has Contact” node is shared now?

The only thing that sharing the “has contact” node does, is make it a little more performant (as the engine only checks for ground contact once instead of 3 times).

What makes the real difference is that this is using impulses, which are additional. So for example, if you apply an upwards impulse, it doesn’t set the horizontal velocity to zero. (At least, that’s my guess)

Ok. What exactly is the difference between setting a certain velocity straight ahead and setting a certain impulse straight ahead? Is it just the way the speed is calculated? It’s calculated with mass in mind with the impulse and not with the velocity?

Velocity -> https://en.wikipedia.org/wiki/Velocity
Impulse -> https://en.wikipedia.org/wiki/Impulse_(physics)

@BlackGoku36 @Armored_Blob Cheers to you both, I think a simple take away in terms of using Armory3D (for anyone else reading) is that using the “Apply Impulse” node for both moving and jumping allows for a nice momentum based jump, while using “Set Velocity” for either/or both doesn’t allow for such a natural momentum based jump.

And the “Get Transform” and “Vector From Transform” nodes should be avoided if you want any natural/non animation based physics.

3 Likes

Good to know this is solved.

I wouldn’t say that you can’t use set velocity for natural, physics based movements. It’s more that you have to be careful to avoid accidentally setting any of the 3 axis’ velocity to zero.

So, for example, you could get the objects velocity, turn it into a vector and then on moving/jumping add a new vector (with the direction of movement desired) and then set that as the new velocity. The trick is adding the new vector to the current velocity, rather using it to replace the current velocity.

Does that make sense?

2 Likes

I think I need to do some reading about the principles of force, velocity and impulse I appreciate the help tho.

I also wonder for a controllable human character if using impulse/velocity or force to make them run is a good idea, that seems more suited to a vehicle. Perhaps just using impulse for the jump is a better idea.

I ended up trying that bool, branch, impulse node setup it works well , a good way to do a physics based jump with a simple transate movement system, thanks.

1 Like

I have spent a while ( the last week maybe ) trying to put together a player controller for a 3rd/1st person shooter type game and it is actually pretty difficult to get it walking around the environment and getting it to walk up and down hills at the right speed, not walk up hill that are too steep, etc. The way I ended up implementing it was with a Haxe trait for a RigidBody and essentially setting the velocity of the object at every frame based on contacts and user input ( and maybe some ray-casts ). It was the only thing that gave control over the player and still didn’t go through walls.

When I finish it I will see about updating the Armory bundled third and first person controller scripts with it.

3 Likes

I’ve spent more time using armory and now better understand how vectors work in relation to impulse, velocity and force. I made a little game from scratch with a static camera and it works as expected.

But the game really want to make has a rotating camera, a third person action game. I can’t use simple X and Y vectors as vectors change every time the camera turns. How can I make an impulse jump forwards (ie. in the direction the character/camera is facing) using my current setup? Everything else is working as expected, it’s just the direction of the jump when I’m also holding the w key.

2 Likes

Two suggestions off the top of my head. The translate along local axis node and the character and camera nodes from the logic pack. I think they at least lead to what you are looking for.

1 Like

I’m already using translate on local axis for normal movement but i want to use impulse to jump, it does work but the X and Y vectors don’t relate to the camera/player rotation so it jumps in a certain direction regardless of the camera/player rotation.

I just want to grab the current X and Y vectors from the camera, The definition of the get rotation node is : “Outputs the current rotation of the set Object as a Vector.”

https://armory3d.org/manual/#/logic_nodes/reference?id=get-rotation

Check out the Vector From Transform node. You can get a vector representing the objects look direction. Then, if you wanted to have something move in the look direction, you can use the Vector Math node to multiply the Look direction by the speed you want it to move in that direction.

2 Likes

Thanks that sounds promising.

1 Like

Awesome thanks, vector from transform > look did the trick, this node setup jumps forward in relation to the camera/player.

2 Likes