Godot 3.5.3
The WASD keys only move to the global axis, and not relative to the kinematic body’s view
Its difficult to explain, when i move forward with the W facing the sun, and then decide to move right., the key will still go to the sun direction and not in relation to the camera’s view. How to fix this?
Here’s my script so far:
func _physics_process(delta):
var input_dir = Vector3.ZERO
if Input.is_action_pressed("ui_up"):
input_dir.z -= 1
if Input.is_action_pressed("ui_down"):
input_dir.z += 1
if Input.is_action_pressed("ui_right"):
input_dir.x += 1
if Input.is_action_pressed("ui_left"):
input_dir.x -= 1
if input_dir != Vector3.ZERO:
input_dir = input_dir.normalized()*speed
if input_dir != Vector3.ZERO:
direction = (transform.basis.x*input_dir.x)+ (transform.basis.z*input_dir.z)
direction.y - 0
direction = direction.normalized()
func _ready ():
Input.set_mouse_mode (Input.MOUSE_MODE_CAPTURED)
func _input (event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation_degrees.x = clamp(head.rotation_degrees.x, -90, 90)