Skip to content

Commit

Permalink
Add rigid collider to bumper
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkehrwald authored and freezy committed Nov 8, 2024
1 parent 66fbf52 commit 3cb0002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal float HitTest(ref NativeColliders colliders, int colliderId, ref BallSt
switch (GetColliderType(ref colliders, colliderId)) {
case ColliderType.Bumper:
return colliders.Circle(colliderId).HitTestBasicRadius(ref newCollEvent, ref InsideOfs, in ball,
ball.CollisionEvent.HitTime, false, false, false);
ball.CollisionEvent.HitTime, direction:false, lateral:true, rigid:false);

case ColliderType.Circle:
return colliders.Circle(colliderId).HitTest(ref newCollEvent, ref InsideOfs, in ball,
Expand Down
16 changes: 10 additions & 6 deletions VisualPinball.Unity/VisualPinball.Unity/VPT/Bumper/BumperApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class BumperApi : CollidableApi<BumperComponent, BumperColliderComponent,
public event EventHandler<SwitchEventArgs> Switch;

private readonly PhysicsEngine _physicsEngine;
private int colliderId;
private int switchColliderId;

public BumperApi(GameObject go, Player player, PhysicsEngine physicsEngine) : base(go, player, physicsEngine)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ void IApiCoil.OnCoil(bool enabled)
collEvent.HitFlag = false;
collEvent.HitOrgNormalVelocity = math.dot(bumpDirection, math.normalize(ballState.Velocity));
collEvent.IsContact = true;
collEvent.ColliderId = colliderId;
collEvent.ColliderId = switchColliderId;
collEvent.IsKinematic = false;
collEvent.BallId = ballId;
var physicsMaterialData = ColliderComponent.PhysicsMaterialData;
Expand All @@ -120,12 +120,16 @@ protected override void CreateColliders(ref ColliderReference colliders,
ref ColliderReference kinematicColliders, float margin)
{
var height = MainComponent.PositionZ;
var switchCollider = new CircleCollider(MainComponent.Position, MainComponent.Radius, height,
height + MainComponent.HeightScale, GetColliderInfo(), ColliderType.Bumper);
var rigidCollider = new CircleCollider(MainComponent.Position, MainComponent.Radius * 0.5f, height,
height + MainComponent.HeightScale, GetColliderInfo(), ColliderType.Circle);
if (ColliderComponent.IsKinematic) {
colliderId = kinematicColliders.Add(new CircleCollider(MainComponent.Position, MainComponent.Radius, height,
height + MainComponent.HeightScale, GetColliderInfo(), ColliderType.Bumper));
switchColliderId = kinematicColliders.Add(switchCollider);
kinematicColliders.Add(rigidCollider);
} else {
colliderId = colliders.Add(new CircleCollider(MainComponent.Position, MainComponent.Radius, height,
height + MainComponent.HeightScale, GetColliderInfo(), ColliderType.Bumper));
switchColliderId = colliders.Add(switchCollider);
colliders.Add(rigidCollider);
}
}

Expand Down

0 comments on commit 3cb0002

Please sign in to comment.