How to apply a force to a 3D rigid body in local coordinates instead of the global ones?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By unfa
:warning: Old Version Published before Godot 3 was released.

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():

func _fixed_process(delta):
	if (Input.is_action_pressed("ui_left")):
	elif (Input.is_action_pressed("ui_right")):
	if (Input.is_action_pressed("ui_up")):
		# walk forward
	elif (Input.is_action_pressed("ui_down")):
		# walk backward
:bust_in_silhouette: Reply From: tiernich

check out this tutorial: movement and rotation

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

specially the Moving in local axes section

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

unfa | 2016-04-01 10:49

But get_transform() can not work in ridgind body can it?My understanding is that get_transform() 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 get_axis, wich works on globall axies. So is there a get_axis_local or something that could work with the ridgid body?

Also, the “func add_force” will apply_impulse 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?

Sojan | 2016-08-01 15:26