28 lines
987 B
C#
28 lines
987 B
C#
using Syntriax.Engine.Core;
|
|
using Syntriax.Engine.Core.Abstract;
|
|
using Syntriax.Engine.Physics2D.Abstract;
|
|
|
|
namespace Syntriax.Engine.Physics2D;
|
|
|
|
public class RigidBody2D : Behaviour, IRigidBody2D
|
|
{
|
|
event IAssignableTransform.OnTransformAssignedEventHandler? IAssignableTransform.OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
|
|
|
private const float LOWEST_ALLOWED_MASS = 0.00001f;
|
|
private float _mass = 1f;
|
|
|
|
|
|
public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault();
|
|
|
|
public Vector2D Velocity { get; set; } = Vector2D.Zero;
|
|
public float AngularVelocity { get; set; } = 0f;
|
|
public bool IsStatic { get; set; } = false;
|
|
|
|
public float Mass { get => _mass; set => _mass = Core.Math.Max(value, LOWEST_ALLOWED_MASS); }
|
|
|
|
ITransform IAssignableTransform.Transform => Transform;
|
|
|
|
|
|
public bool Assign(ITransform transform) => GameObject.Assign(transform);
|
|
}
|