Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | guy7 |
Here’s the script:
extends CharacterBody3D
const MOUSE_SENSITIVITY: float = 0.2
const MOVE_SPEED: float = 3.4
@onready var lookPivot: Node3D = $LookPivot
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-1 * event.relative.x * MOUSE_SENSITIVITY))
lookPivot.rotate_x(deg_to_rad(event.relative.y * MOUSE_SENSITIVITY))
lookPivot.rotation.x = clamp(lookPivot.rotation.x, deg_to_rad(-90), deg_to_rad(90))
func _physics_process(delta):
var inputDir = get_input_direction()
move_and_slide()
func get_input_direction() -> Vector3:
var z: float = (
Input.get_action_strength("ui_w") - Input.get_action_strength("ui_s")
)
var x: float = (
Input.get_action_strength("ui_a") - Input.get_action_strength("ui_d")
)
return Vector3(x, 0, z).normalized()
I’m running on Godot 4.0.2