using Godot; using System; public partial class TestCharacter : CharacterBody3D { [Export] private float _speed = 5.0f; public override void _PhysicsProcess(double delta) { Vector3 velocity = Velocity; // Get the input direction and handle the movement/deceleration. // As good practice, you should replace UI actions with custom gameplay actions. Vector2 inputDir = Input.GetVector("p1_left", "p1_right", "p1_up", "p1_down"); Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized(); if (direction != Vector3.Zero) { velocity.X = direction.X * _speed; velocity.Z = direction.Z * _speed; GetNode("Pivot").LookAt(Position + direction, Vector3.Up); } else { velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed); velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed); } Velocity = velocity; MoveAndSlide(); } }