Godot Version
v4.8.dev2.official [7220d456d]
Question
A really simple issue that I should be able to solve, but all I’ve tried has been to no avail. I have a MeshInstance3D moving across a GridMap. I can’t get the Object to move in a new Forward direction after being rotated 90°. It retains the ‘-Z’ for forward, however I rotate it. It is surely simple, but I’ve tried Local, Global, Basis, transform… and am now totally confused, as the movement remains the same. Either my movement is flawed, or I’m not rotating correctly. What have I missed, please..? Here’s the (simple…) GDScript, and illustrative screenshots. Thanks in advance for shedding light on my problem…
~~~
class_name Barb extends Character
var move_dir : Vector2
func _process(_dt):
pass
if not can_move:
return
handle_movement()
if not move_dir:
return
print(move_dir)
move_command(move_dir)
move_dir = Vector2(0.0,0.0)
func handle_movement():
if Input.is_action_just_pressed(“Move_Forward”):
move_dir = Vector2(0.0,1.0)
return
if Input.is_action_just_pressed("Move_Back"):
move_dir = Vector2(0.0,-1.0)
return
if Input.is_action_just_pressed("Step_Left"):
move_dir = Vector2(1.0,0.0)
return
if Input.is_action_just_pressed("Step_Right"):
move_dir = Vector2(-1.0,0.0)
return
if Input.is_action_just_pressed("Rotate_Right"):
#rotate_object_local(Vector3.UP,deg_to_rad(int(-90)))
transform.basis = transform.basis.rotated(Vector3.UP,deg_to_rad(int(-90)))
if Input.is_action_just_pressed("Rotate_Left"):
#rotate_object_local(Vector3.UP,deg_to_rad(int(90)))
transform.basis = transform.basis.rotated(Vector3.UP,deg_to_rad(int(90)))
~~~
This is the non-rotated position…
… and this is rotated through 90°…
The character always responds to a ‘Forward’ command in the direction of the Blue, ‘-Z’ arrow.
Again, apologies for the formatting; it’s a French keyboard and nothing works better than this. Sorry. The indentations are correct in the editor…



