E 0:00:00:0694 :0 @ System.Object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void* , System.Object ): System.InvalidCastException: Unable to cast object of type 'PlayerScript' to type 'Godot.CharacterBody3D'.
<C++ Error> System.InvalidCastException
<C++ Source> :0 @ System.Object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void* , System.Object )
<Stack Trace> :0 @ System.Object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void* , System.Object )
VariantUtils.generic.cs:385 @ T Godot.NativeInterop.VariantUtils.ConvertTo<T >(Godot.NativeInterop.godot_variant& )
MovementController_ScriptProperties.generated.cs:18 @ Boolean MovementController.SetGodotClassPropertyValue(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.godot_variant& )
CSharpInstanceBridge.cs:57 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Set(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant* )
Happens in the MovementController if the playerscript on the Characterbody3D node is not inheriting from Characterbody3D.
Movementcontroller code:
`public partial class MovementController : Node
{
[Export] private CharacterBody3D body;
[Export] private float speed = 10f;
[Export] private float speedMod = 1f;
[Export] private float rotationSpeed = 5f;
[Export] private float gravity = -9f;
[Export] private float drag;
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public override void _PhysicsProcess(double delta)
{
Move(delta);
ApplyGravity(delta);
body.MoveAndSlide();
}
private void ApplyGravity(double delta)
{
if (body.IsOnFloor())
return;
body.Velocity = new Vector3(body.Velocity.X, body.Velocity.Y + gravity * drag * (float)delta, body.Velocity.Z);
}
private void Move(double delta)
{
//Input get action strength to get a vector
Vector2 input = InputManager.i.InputVector;
Vector3 move = new Vector3(input.X, 0.0f, input.Y);
move = move.Normalized();
body.Velocity = move * speed * speedMod * (float)delta;
if (move != Vector3.Zero)
{
float y = (float)Mathf.LerpAngle(body.Rotation.Y, Mathf.Atan2(move.X, move.Z), delta * rotationSpeed);
body.Rotation = new Vector3(body.Rotation.X, y, body.Rotation.Z);
}
}
}
`