stable collisions
This commit is contained in:
@@ -34,8 +34,6 @@ namespace PhysicsEngine
|
||||
TorqueAccumulator += torque;
|
||||
}
|
||||
|
||||
// --- Impulse Methods ---
|
||||
|
||||
public void ApplyImpulse(Vector2 impulse)
|
||||
{
|
||||
if (IsStatic) return;
|
||||
@@ -46,10 +44,8 @@ namespace PhysicsEngine
|
||||
{
|
||||
if (IsStatic) return;
|
||||
|
||||
// Direct linear velocity change
|
||||
Velocity += impulse * InverseMass;
|
||||
|
||||
// Rotate local offset into world space based on body rotation
|
||||
float cos = MathF.Cos(Rotation);
|
||||
float sin = MathF.Sin(Rotation);
|
||||
Vector2 worldOffset = new Vector2(
|
||||
@@ -57,7 +53,6 @@ namespace PhysicsEngine
|
||||
localOffset.X * sin + localOffset.Y * cos
|
||||
);
|
||||
|
||||
// 2D Cross product for torque: r x J
|
||||
float torque = worldOffset.X * impulse.Y - worldOffset.Y * impulse.X;
|
||||
AngularVelocity += torque * InverseInertia;
|
||||
}
|
||||
@@ -66,19 +61,14 @@ namespace PhysicsEngine
|
||||
{
|
||||
if (IsStatic) return;
|
||||
|
||||
// Direct linear velocity change
|
||||
Velocity += impulse * InverseMass;
|
||||
|
||||
// Offset from center of mass in world space
|
||||
Vector2 worldOffset = worldPosition - Position;
|
||||
|
||||
// 2D Cross product for torque: r x J
|
||||
float torque = worldOffset.X * impulse.Y - worldOffset.Y * impulse.X;
|
||||
AngularVelocity += torque * InverseInertia;
|
||||
}
|
||||
|
||||
// --- Other Useful Methods to Consider ---
|
||||
|
||||
public void ApplyForceAtWorldPosition(Vector2 force, Vector2 worldPosition)
|
||||
{
|
||||
if (IsStatic) return;
|
||||
|
||||
Reference in New Issue
Block a user