2024-01-23 18:39:25 +03:00
|
|
|
using Syntriax.Engine.Core;
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
|
|
|
using Syntriax.Engine.Physics2D.Abstract;
|
|
|
|
|
|
|
|
namespace Syntriax.Engine.Physics2D;
|
|
|
|
|
2024-09-30 12:18:13 +03:00
|
|
|
public class RigidBody2D : Behaviour, IRigidBody2D
|
2024-01-23 18:39:25 +03:00
|
|
|
{
|
2024-11-23 23:14:44 +03:00
|
|
|
event IAssignableTransform.OnTransformAssignedEventHandler? IAssignableTransform.OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
2024-01-23 18:39:25 +03:00
|
|
|
|
2024-01-27 14:58:50 +03:00
|
|
|
private const float LOWEST_ALLOWED_MASS = 0.00001f;
|
|
|
|
private float _mass = 1f;
|
|
|
|
|
2024-01-23 18:39:25 +03:00
|
|
|
|
|
|
|
public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault();
|
|
|
|
|
|
|
|
public Vector2D Velocity { get; set; } = Vector2D.Zero;
|
|
|
|
public float AngularVelocity { get; set; } = 0f;
|
2024-01-24 19:21:53 +03:00
|
|
|
public bool IsStatic { get; set; } = false;
|
2024-01-23 18:39:25 +03:00
|
|
|
|
2024-01-27 14:58:50 +03:00
|
|
|
public float Mass { get => _mass; set => _mass = Core.Math.Max(value, LOWEST_ALLOWED_MASS); }
|
|
|
|
|
2024-01-23 18:39:25 +03:00
|
|
|
ITransform IAssignableTransform.Transform => Transform;
|
|
|
|
|
|
|
|
|
|
|
|
public bool Assign(ITransform transform) => GameObject.Assign(transform);
|
|
|
|
}
|