After rotating how to move forward with the new rotation angle.

Godot Version

Godot Engine v4.2.1

Question

Hello I’m very new to godot and everything about gamedev.
I’m currently creating a tank shooting game but I’m stuck at the movement.
so to rotate my object/player I used this:

extends CharacterBody3D
@export var rot_speed = 10

func _physics_process(delta: float) → void:

if Input.is_action_pressed(“Left”):
self.rotation.y += delta * rot_speed
if Input.is_action_pressed(“Right”):
self.rotation.y -= delta * rot_speed

I thought rotating it was pretty straight forward so now my next mission was to move the object forward a direction. I thought just adding this would do it:

if Input.is_action_pressed(“Forward”):
self.position.z += delta
if Input.is_action_pressed(“Back”):
self.position.z -= delta

what ended up happening was it wasn’t moving to the object new Z axis position or rotation. I’m guessing I have to update something to get the new position, how do I got about that?

try pasting this

extends CharacterBody3D
@export var rot_speed = 10
@export var move_speed = 10

func _physics_process(delta: float) -> void:

	if Input.is_action_pressed("Left"):
		self.rotation.y += delta * rot_speed
	if Input.is_action_pressed("Right"):
		self.rotation.y -= delta * rot_speed
	if Input.is_action_pressed("Forward"):
		self.position.z += delta * move_speed
	if Input.is_action_pressed("Back"):
		self.position.z -= delta * move_speed

probably the cause was the double quotes you used were not of the valid type

that still has the same issue that I had.


after turning I want it to go along the red marker not the green as illustrated up top.