mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Rigidbody2D Get/Set Linear and Angular Velocity
This commit is contained in:
@@ -300,6 +300,46 @@ static class ScriptGlue
|
||||
rotation = rigidBody.GetAngle();
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_GetLinearVelocity")]
|
||||
static void Rigidbody2D_GetLinearVelocity(UUID entityId, out float2 velocity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
velocity = rigidBody.GetLinearVelocity();
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_SetLinearVelocity")]
|
||||
static void Rigidbody2D_SetLinearVelocity(UUID entityId, in float2 velocity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
rigidBody.SetLinearVelocity(velocity);
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_GetAngularVelocity")]
|
||||
static void Rigidbody2D_GetAngularVelocity(UUID entityId, out float velocity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
velocity = rigidBody.GetAngularVelocity();
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_SetAngularVelocity")]
|
||||
static void Rigidbody2D_SetAngularVelocity(UUID entityId, in float velocity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
rigidBody.SetAngularVelocity(velocity);
|
||||
}
|
||||
|
||||
#endregion Rigidbody2D
|
||||
|
||||
#region Physics2D
|
||||
|
||||
@@ -385,6 +385,9 @@ namespace GlitchyEngine.World
|
||||
|
||||
private int _runtimeBody = 0;
|
||||
|
||||
//private float _linearDamping = 0.0f;
|
||||
//private float _angularDamping = 0.01f;
|
||||
|
||||
protected internal b2Body* RuntimeBody
|
||||
{
|
||||
[Inline]
|
||||
@@ -392,6 +395,30 @@ namespace GlitchyEngine.World
|
||||
[Inline]
|
||||
set mut => _runtimeBody = (int)(void*)value;
|
||||
}
|
||||
|
||||
/*public float LinearDamping
|
||||
{
|
||||
get => _linearDamping;
|
||||
set mut
|
||||
{
|
||||
_linearDamping = value;
|
||||
|
||||
if (RuntimeBody != null)
|
||||
Box2D.Body.SetLinearDamping(RuntimeBody, _linearDamping);
|
||||
}
|
||||
}
|
||||
|
||||
public float AngularDamping
|
||||
{
|
||||
get => _angularDamping;
|
||||
set mut
|
||||
{
|
||||
_angularDamping = value;
|
||||
|
||||
if (RuntimeBody != null)
|
||||
Box2D.Body.SetAngularDamping(RuntimeBody, _angularDamping);
|
||||
}
|
||||
}*/
|
||||
|
||||
public float2 GetPosition()
|
||||
{
|
||||
@@ -436,6 +463,40 @@ namespace GlitchyEngine.World
|
||||
Box2D.Body.SetTransform(RuntimeBody, pos, angle);
|
||||
}
|
||||
}
|
||||
|
||||
public float2 GetLinearVelocity()
|
||||
{
|
||||
if (RuntimeBody != null)
|
||||
{
|
||||
Box2D.b2Vec2 vec = Box2D.Body.GetLinearVelocity(RuntimeBody);
|
||||
|
||||
return *(float2*)&vec;
|
||||
}
|
||||
|
||||
return .Zero;
|
||||
}
|
||||
|
||||
public void SetLinearVelocity(float2 velocity)
|
||||
{
|
||||
if (RuntimeBody != null)
|
||||
Box2D.Body.SetLinearVelocity(RuntimeBody, velocity);
|
||||
}
|
||||
|
||||
public float GetAngularVelocity()
|
||||
{
|
||||
if (RuntimeBody != null)
|
||||
{
|
||||
return Box2D.Body.GetAngularVelocity(RuntimeBody);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetAngularVelocity(float velocity)
|
||||
{
|
||||
if (RuntimeBody != null)
|
||||
Box2D.Body.SetAngularVelocity(RuntimeBody, velocity);
|
||||
}
|
||||
}
|
||||
|
||||
/*struct InternalBug
|
||||
|
||||
Reference in New Issue
Block a user