Skip to content

Commit

Permalink
Merge pull request #39 from technologists-team/damping
Browse files Browse the repository at this point in the history
Bodies damping
  • Loading branch information
Tornado-Technology authored Aug 2, 2024
2 parents 630e16f + 898b845 commit b876607
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion Hypercube.Client/Entities/Systems/Physics/PhysicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Entities.Systems.Physics;
using Hypercube.Shared.Physics;
using Hypercube.Shared.Physics.Shapes;
using SharedPhysicsSystem = Hypercube.Shared.Entities.Systems.Physics.PhysicsSystem;

namespace Hypercube.Client.Entities.Systems.Physics;
Expand Down
6 changes: 6 additions & 0 deletions Hypercube.Shared/Entities/Systems/Physics/PhysicsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public Vector2 Position
}

public Vector2 LinearVelocity { get; set; }
public Vector2 LinearDamping { get; set; } = Vector2.One;

public float Angle { get; set; }
public float AngularVelocity { get; }
public float AngularDamping { get; set; } = 1f;

public Vector2 Force { get; set; }

Expand Down Expand Up @@ -79,9 +81,13 @@ public void Update(float deltaTime, Vector2 gravity)

LinearVelocity += acceleration * deltaTime;
LinearVelocity += gravity * deltaTime;

LinearVelocity *= LinearDamping;

Position += LinearVelocity * deltaTime;
Angle += AngularVelocity * deltaTime;

Angle *= AngularDamping;

Force = Vector2.Zero;
}
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared/Physics/IBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ public interface IBody

Vector2 Position { get; }
Vector2 LinearVelocity { get; set; }
Vector2 LinearDamping { get; set; }

float Angle { get; }
float AngularVelocity { get; }
float AngularDamping { get; }

Vector2 Force { get; }

Expand Down

0 comments on commit b876607

Please sign in to comment.