var gravity = 9.8
var location = Vector3()
var capncrunch = Vector3()
export var speed = 7
export var jump_height = 9
var velocity = Vector3()

func getinput():
velocity = Vector3()
if Input.is
actionpressed('uiright'):
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.is
actionpressed("uiforward"):
velocity.z -= 1
if Input.isactionpressed("ui_backwards"):
velocity.z += 1
velocity = velocity.normalized() * speed

func physicsprocess(delta):
getinput()
velocity = move
andslide(velocity)
move
and_slide(capncrunch, Vector3.UP)

``````if Input.is_action_just_pressed("jump"):
if is_on_floor():
capncrunch.y = jump_height

if not is_on_floor():
capncrunch.y -= gravity * delta
move_and_slide(capncrunch, Vector3.UP)
``````
in Engine

Here's the code I use:

``````if Input.is_action_pressed("move_forward"):
direction += transform.basis.z
elif Input.is_action_pressed("move_backward"):
direction -= transform.basis.z
if Input.is_action_pressed("move_left"):
direction += transform.basis.x
elif Input.is_action_pressed("move_right"):
direction -= transform.basis.x
``````

Then I use the moveandslide() function with direction(which is a vector3). Out of total curiosity why do you have a variable called capncrunch? =)

by (370 points)
selected

thank you so much!!!! i retried it and it worked

glad to hear it! I'm still curious as to why you named your variable after a breakfast cereal though, =D

it was in a random tutorial

+1 vote

Use `global_transform.basis.xform(Vector3)` to get a local vector.

``````move_and_slide(global_transform.basis.xform(capncrunch), Vector3.UP)

#or for a third person camera
move_and_slide(Camera.global_transform.basis.xform(capncrunch), Vector3.UP)
``````
by (3,201 points)

it didn't work just when i pressed a button to move forward it would just move north not actually where the character is facing

Is the camera a child rotating in the kinematicbody parent? You need to reference the node want to move relative to.

Yes it is but ive been stuck on this problem for hours :(