Godot Version
4.3
Question
Im trying to make my character move with "WASD" Controls, however when the characterbody3d is rotated at whatever angle, the controls are completely inverted. How do i make them connect to each other?
CODE:
extends CharacterBody3D
@onready var animated_sprite_2d = $CanvasLayer/GunBase/AnimatedSprite2D
@onready var ray_cast_3d = $Camera/RayCast3D
var health = 5
const SPEED = 10.0
const MOUSE_SENS = 0.25
var can_shoot = true
var dead = false
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
animated_sprite_2d.animation_finished.connect(shoot_anim_done)
func _input(event):
if dead:
return
if event is InputEventMouseMotion:
rotation_degrees.y -= event.relative.x * MOUSE_SENS
func _process(delta):
if dead:
return
if Input.is_action_just_pressed(“Shoot”):
$AudioStreamPlayer.play()
shoot()
$CanvasLayer/ShrimpCount.text=str(Global.ShrimpEaten)
if Input.is_action_just_pressed(“retry”):
get_tree().change_scene_to_file(“res://world.tscn”)
func _physics_process(delta):
if dead:
return
var input_dir = Input.get_vector(“left”, “right”, “forward”,“backwards”)
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
if not is_on_floor():
velocity += get_gravity() * delta