+5 votes

I'm trying to make a very simple game just to walk around a scenery, but making the character walk in the direction of which he's facing seems like impossible.

I can rotate the character but he's always walking along the global axis, instead of forward relative it it's rotation.

My code for player object:

extends RigidBody

# member variables here, example:
# var a=2
# var b="textvar"

var turn_speed = 60
var walk_speed = 100

func _ready():
    set_fixed_process(true)
    pass

func _fixed_process(delta):
    if (Input.is_action_pressed("ui_left")):
        rotate_y(-turn_speed*0.1*delta)
    elif (Input.is_action_pressed("ui_right")):
        rotate_y(turn_speed*0.1*delta)

    if (Input.is_action_pressed("ui_up")):
        # walk forward
    elif (Input.is_action_pressed("ui_down")):
        # walk backward
in Engine by (205 points)

1 Answer

+1 vote

check out this tutorial: movement and rotation

give me the basis to start moving things in 3D space :D

specially the Moving in local axes section

by (429 points)

The problem is that translate() causes objects to glitch out in the physics simulation (breath through walls) because it makes the object teleport between discreet locations every frame, instead of following a steady, force-driven motion

But gettransform() can not work in ridgind body can it?My understanding is that gettransform() does not use physics, and ignores all rules such as gravity, friction, and colisions that modify motion; wich makes it virtually unusable to make a player (plz correct me if I am wrong). Usually for physics with ridgid body we use getaxis, wich works on globall axies. So is there a getaxis_local or something that could work with the ridgid body?

Also, the "func addforce" will applyimpulse on 0, 1, and 2 (x y and z respectivly axees), are those locall or global, or can they be eather depending on the get_axis (or whatever else you will use) function?

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 [email protected] with your username.