# 3D directional jumping

Attention Topic was automatically imported from the old Question2Answer platform.

I’m working on a 3D platformer and I need the character to be able to jump off walls. I’m using a Kinematic body and already have code for getting on the walls and whatnot, but I can’t seem to get them to jump other than using the translate function as a sort of proof-of-concept. This is used along with the character’s xform.basis to make sure they jump based on where they’re facing, but I would prefer applying the character’s jump force instead.

Code example:

``````var jmp_spd = Vector3(0,-9.8,0)

if col_result == ['back']:
if !jmp_att :
lv = Vector3(0,0.0000001,0)
elif jmp_att:
translate(mesh_xform.basis.xform(Vector3(-jmp_spd.y * .33,jmp_spd.y * .25 ,0)))
``````

I tried applying the jump speed along the X axis using the character’s horizontal and vertical velocity, but it never quite applies. Any help or advice is appreciated.

To do a wall jump you need to kick off the wall. And to kick off the wall, you’ll need the wall’s normal.

``````var normal = get_slide_collision(0).normal
lv += normal * wall_power
#..Along with some vertical speed.
lv += UP * wall_power
``````

Where `UP` is your vector pointing up.
And `wall_power` is the strength of the wall jump.
It could have been two separate variables to customize the jump further.

This works pretty wonderfully (with a few tweaks for my needs).

Sorry for the added question, but how would I go about for a diagonal jump as well?

mstfacmly | 2018-04-22 02:13

You mean like add velocity parallel to the wall?

SIsilicon | 2018-04-22 20:32

Essentially, yes.

mstfacmly | 2018-04-22 22:27

Ok then.
What you could do is store a vector created by…

``````#mod_lv is a global variable
mod_lv = lv.slide(UP).slide(get_slide_collision(0).normal)
``````

And then applying it later.

``````lv += mod_lv * wall_power
``````

That first code bit should be executed within the if statement in which you test for wall collision.

``````if is_on_wall():
#First piece of code
``````

I haven’t tested this yet, but it should take the velocity parallel to the wall on impact and add it back when wall jumping.

SIsilicon | 2018-04-23 21:26

Fantastic! That’s exactly what I needed! Thank you!

mstfacmly | 2018-04-23 22:41