I have found something for C# too (but don't trust it too much, i have no knowledge of C#).
Let me know if we have the same problems.
This is a full-script in C#, dont know if resolve your problem, but should be related!
using Godot;
using System;
public partial class CharacterController : CharacterBody3D
{
public const float Speed = 5.0f;
public const float JumpVelocity = 4.5f;
private Camera3D Camera;
private CharacterBody3D Character;
// Get the gravity from the project settings to be synced with RigidBody nodes.
public float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
const float MouseSensitivityX = 1.0f;
const float MouseSensitivityY = 1.0f;
public override void _Ready()
{
Camera = GetNode<Camera3D>("Neck/Camera3D");
Character = this;
}
public override void _PhysicsProcess(double delta)
{
Vector3 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
velocity.Y -= gravity * (float)delta;
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
velocity.Y = JumpVelocity;
// 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("Left", "Right", "Up", "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;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, Speed);
}
Velocity = velocity;
MoveAndSlide();
}
public override void _UnhandledInput(InputEvent @Event)
{
if (@Event is InputEventMouseButton)
{
Input.MouseMode = Input.MouseModeEnum.Captured;
} else if (@Event.IsActionPressed("ui_cancel"))
{
Input.MouseMode = Input.MouseModeEnum.Visible;
}
if (Input.MouseMode == Input.MouseModeEnum.Captured)
{
if (@Event is InputEventMouseMotion MouseMotion)
{
Character.RotateY(Convert.ToSingle(-MouseMotion.Relative.X * (MouseSensitivityY/100)));
Vector3 CurrentCameraRotation = Camera.Rotation;
CurrentCameraRotation.X += Convert.ToSingle(-MouseMotion.Relative.Y * (MouseSensitivityX / 100));
CurrentCameraRotation.X = Mathf.Clamp(CurrentCameraRotation.X, Mathf.DegToRad(-90), Mathf.DegToRad(90));
Camera.Rotation = CurrentCameraRotation;
}
}
}
}