how do i move my 3d character using local co-ordinates?

: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

was my answer in your previous question any good? It uses local coordinates.

Millard | 2020-11-19 21:07

no it didnt unfortunately

James122333 | 2020-11-19 21:16

your code would be a lot easier to read if you select it all and press the {} icon. =)

Millard | 2020-11-19 21:25