How do i get my 3d character to move where it's facing???

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By James122333
ar gravity = 9.8

var location = Vector3()
var capncrunch = Vector3()
export var speed = 7
export var jump_height = 9
var velocity = Vector3()

func get_input():
velocity = Vector3()
if Input.is_action_pressed(‘ui_right’):
velocity.x += 1
if Input.is_action_pressed(‘ui_left’):
velocity.x -= 1
if Input.is_action_pressed(“ui_forward”):
velocity.z -= 1
if Input.is_action_pressed(“ui_backwards”):
velocity.z += 1
velocity = velocity.normalized() * speed

func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)
move_and_slide(global_transform.basis.xform(capncrunch), Vector3.UP)

if Input.is_action_just_pressed("jump"):
	if is_on_floor():
		capncrunch.y = jump_height

if not is_on_floor():
	capncrunch.y -= gravity * delta

Means do you want to make a fps type game in Godot?
Then you can search for Garbaj fps series. It will teach you
how to make a fps in Godot.

Dinoking | 2020-11-20 04:22

:bust_in_silhouette: Reply From: AnindyaRoy

Change all velocity.x, velocity.z to velocity.basis.x, velocity.basis.z

:bust_in_silhouette: Reply From: stormreaver

Each object has both a local and global transform (transform and global_transform, respectively). Which one you use depends on various circumstances, but the transforms are what you need. Assuming you are executing a script from within the object class itself, you can get the local direction vector with:

transform.basis.z

and the global direction vector with:

global_transform.basis.z

Then you can use move_and_collide or move_and_slide with this vector.