Godot Version
4
Question
I have been coding a first person game and my movement is wack, when i press W i go left and S is right Etc… what do i do? what is wrong?
Code
extends CharacterBody3D
@export var move_speed := 5.0
@export var mouse_sensitivity := 0.2
var motion_velocity: Vector3 = Vector3.ZERO
var rotation_y: float = 0.0
var camera_pitch: float = 0.0
@onready var camera: Camera3D = $Camera3D
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$glockityglook.visible = false
$ARBLABLA.visible = true
$mossshotgun.visible = false
func _process(delta):
if Input.is_action_just_pressed(“ui_cancel”):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed(“option1”):
$glockityglook.visible = false
$ARBLABLA.visible = true
$mossshotgun.visible = false
if Input.is_action_just_pressed(“option2”):
$glockityglook.visible = false
$ARBLABLA.visible = false
$mossshotgun.visible = true
if Input.is_action_just_pressed(“option3”):
$glockityglook.visible = true
$ARBLABLA.visible = false
$mossshotgun.visible = false
func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
rotation_y -= event.relative.x * mouse_sensitivity
rotation_degrees.y = rotation_y
camera_pitch -= event.relative.y * mouse_sensitivity
camera_pitch = clamp(camera_pitch, -90.0, 90.0)
camera.rotation_degrees.x = camera_pitch
func _physics_process(delta):
var input_dir: Vector3 = Vector3.ZERO
input_dir.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_dir.z = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_dir = input_dir.normalized()
var forward = -transform.basis.z.normalized()
var right = transform.basis.x.normalized()
var movement_dir = (forward * input_dir.z) + (right * input_dir.x)
movement_dir.y = 0
motion_velocity = movement_dir * move_speed
velocity = motion_velocity
move_and_slide()