2022-12-28 21:57:34 +01:00
|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public class Entity : KinematicBody
|
|
|
|
{
|
2023-01-03 17:46:55 +01:00
|
|
|
public Vector3 Velocity { get; set; } = Vector3.Zero;
|
|
|
|
public float RotationalVelocity { get; set; } = 0;
|
2022-12-28 21:57:34 +01:00
|
|
|
|
2023-10-27 23:00:54 +02:00
|
|
|
/** Defines the angle in plane coordinates, 0 => pointing to the right/east, pi/2 pointing up/north, range [-pi,pi]. */
|
|
|
|
public float PlaneAngle
|
|
|
|
{
|
|
|
|
get => GlobalTransform.basis.x.SignedAngleTo(Vector3.Right.Rotated(Vector3.Up, Mathf.Pi * 0.5f), -Vector3.Up);
|
|
|
|
set => GlobalTransform = new Transform(new Basis(Vector3.Up, value + Mathf.Pi * 0.5f), GlobalTranslation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public float CalcShortestPlaneRotationToTarget(Vector3 globalTargetPosition)
|
|
|
|
{
|
|
|
|
float angleToTarget = Vector3.Right.SignedAngleTo(globalTargetPosition - GlobalTranslation, Vector3.Up);
|
|
|
|
float currentAngle = PlaneAngle;
|
|
|
|
|
|
|
|
float delta = angleToTarget - currentAngle;
|
|
|
|
delta += (delta > Mathf.Pi) ? -Mathf.Pi * 2 : (delta < -Mathf.Pi) ? Mathf.Pi * 2 : 0;
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
2022-12-28 21:57:34 +01:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|