0 votes

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
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.is
velocity.z -= 1
if Input.isactionpressed("ui_backwards"):
velocity.z += 1
velocity = velocity.normalized() * speed

func physicsprocess(delta):
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 by (58 points)

2 Answers

0 votes
Best answer

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 (386 points)
selected by

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,233 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 :(

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.