GodotComponentTest/entities/Entity.cs

35 lines
1.1 KiB
C#

using System;
using Godot;
public class Entity : KinematicBody {
[Flags]
public enum EntityMaskEnum {
Obstacle = 1 << 1,
Ground = 1 << 2,
Water = 1 << 3
}
[Export(PropertyHint.Flags, "Obstacle,Ground,Water")]
public int EntityMask { get; set; }
public Vector3 Velocity { get; set; } = Vector3.Zero;
public float RotationalVelocity { get; set; } = 0;
/**
* Defines the angle in plane coordinates, 0 => pointing to the right/east, pi/2 pointing up/north, range [-pi,pi].
*/
public float PlaneAngle {
get => Globals.CalcPlaneAngle(GlobalTransform);
set => GlobalTransform = new Transform(new Basis(Vector3.Up, value + Mathf.Pi * 0.5f), GlobalTranslation);
}
public float CalcShortestPlaneRotationToTargetDirection(Vector3 globalTargetDirection) {
float angleToTarget = Vector3.Right.SignedAngleTo(globalTargetDirection, 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;
}
}