Move and rotate

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By imekon

I have a 3D spatial object that rotates about the Y axis:

core.rotate_y(3 * delta)

I also want it to move to the left or right (i.e. along the x axis), so I do the following:

var x = 0

if Input.is_action_pressed("ui_left"):
	x -= delta * 10
if Input.is_action_pressed("ui_right"):
	x += delta * 10
	
if x < -4:
	x = -4
	
if x > 4:
	x = 4

core.translate(Vector3(x, 0, 0))

Instead of it spinning and moving left or right, it moves in a circle instead of a straight line. If I choose a different axis (say y or z) then the translate makes sense.

How do I get the object to spin about the y axis and move a long the x axis controlled by the left/right arrow keys?

:bust_in_silhouette: Reply From: imekon

I need a global translate and a local rotate, as in:

var x = 0
if Input.is_action_pressed("ui_left"):
	x = -delta

if Input.is_action_pressed("ui_right"):
	x = delta
	
player.global_translate(Vector3(x * SPEED, 0, 0))
player.rotate(Vector3(0, 1, 0), delta)