0 votes

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?

asked Aug 24, 2018 in Engine by imekon (229 points)

1 Answer

0 votes

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)
answered Aug 24, 2018 by imekon (229 points)
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 How to use this Q&A? before posting your first questions.