how to move to forward of character?

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

rotate_y apply rotate to character , but local gizmo is not rotated.
when i push key_up(move to forward),it move to forward of global.
how to move to local forward(local z) of character?
func get_input(delta):
vec = Vector3()
if Input.is_key_pressed(KEY_UP):
vec.z += -1 * speed
if Input.is_key_pressed(KEY_RIGHT):
rotate_y(deg2rad(-1))
move_and_slide(vec)

:bust_in_silhouette: Reply From: Fyrion

I assume getting localZ and put +/- int to it could work?

thanks.
yes i think this is work well by local rotation of character.
but i dont know how to use local rotation.
i make this code.
extends KinematicBody
var vec = Vector3()
var speed = 10

func _physics_process(delta):
	vec = Vector3()
	if Input.is_key_pressed(KEY_UP):
		vec += -global_transform.basis.z * speed
	if Input.is_key_pressed(KEY_RIGHT):
		rotate_y(deg2rad(-1))
	if Input.is_key_pressed(KEY_LEFT):
		rotate_y(deg2rad(1))
	move_and_slide(vec)

this is rotate.

but Do not turn around the character
This seems to be centered around the camera

but this code rotation by camera origin.
how to rotate by character origin?

bgegg | 2019-08-05 08:37