2023-12-29 09:26:43 +01:00
|
|
|
using System;
|
2022-12-28 21:57:34 +01:00
|
|
|
using Godot;
|
|
|
|
|
2023-11-18 22:11:34 +01:00
|
|
|
public class Entity : KinematicBody {
|
2023-12-29 09:26:43 +01:00
|
|
|
[Flags]
|
|
|
|
public enum EntityMaskEnum {
|
|
|
|
Obstacle = 1 << 1,
|
|
|
|
Ground = 1 << 2,
|
|
|
|
Water = 1 << 3
|
|
|
|
}
|
|
|
|
|
|
|
|
[Export(PropertyHint.Flags, "Obstacle,Ground,Water")]
|
|
|
|
public int EntityMask { get; set; }
|
|
|
|
|
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-11-18 22:11:34 +01:00
|
|
|
/**
|
|
|
|
* Defines the angle in plane coordinates, 0 => pointing to the right/east, pi/2 pointing up/north, range [-pi,pi].
|
|
|
|
*/
|
|
|
|
public float PlaneAngle {
|
2023-11-10 12:22:17 +01:00
|
|
|
get => Globals.CalcPlaneAngle(GlobalTransform);
|
2023-10-27 23:00:54 +02:00
|
|
|
set => GlobalTransform = new Transform(new Basis(Vector3.Up, value + Mathf.Pi * 0.5f), GlobalTranslation);
|
|
|
|
}
|
2023-11-18 22:11:34 +01:00
|
|
|
|
|
|
|
public float CalcShortestPlaneRotationToTargetDirection(Vector3 globalTargetDirection) {
|
2023-11-01 12:33:04 +01:00
|
|
|
float angleToTarget = Vector3.Right.SignedAngleTo(globalTargetDirection, Vector3.Up);
|
2023-10-27 23:00:54 +02:00
|
|
|
float currentAngle = PlaneAngle;
|
|
|
|
|
|
|
|
float delta = angleToTarget - currentAngle;
|
|
|
|
|
2023-11-18 22:11:34 +01:00
|
|
|
delta += delta > Mathf.Pi ? -Mathf.Pi * 2 : delta < -Mathf.Pi ? Mathf.Pi * 2 : 0;
|
|
|
|
return delta;
|
2022-12-28 21:57:34 +01:00
|
|
|
}
|
|
|
|
}
|