Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bumper animations #489

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Unity.Jobs;
using Unity.Mathematics;
using VisualPinball.Engine.Common;
using UnityEngine;

namespace VisualPinball.Unity
{
Expand Down Expand Up @@ -128,10 +129,10 @@ public void Execute()
while (enumerator.MoveNext()) {
ref var bumperState = ref enumerator.Current.Value;
if (bumperState.RingItemId != 0) {
BumperRingAnimation.Update(ref bumperState.RingAnimation, DeltaTimeMs);
BumperRingAnimation.Update(ref bumperState.RingAnimation, PhysicsConstants.PhysicsStepTime / 1000f);
}
if (bumperState.SkirtItemId != 0) {
BumperSkirtAnimation.Update(ref bumperState.SkirtAnimation, DeltaTimeMs);
BumperSkirtAnimation.Update(ref bumperState.SkirtAnimation, PhysicsConstants.PhysicsStepTime / 1000f);
}
}
}
Expand Down Expand Up @@ -164,7 +165,7 @@ public void Execute()
using (var enumerator = TriggerStates.GetEnumerator()) {
while (enumerator.MoveNext()) {
ref var triggerState = ref enumerator.Current.Value;
TriggerAnimation.Update(ref triggerState.Animation, ref triggerState.Movement, in triggerState.Static, DeltaTimeMs);
TriggerAnimation.Update(ref triggerState.Animation, ref triggerState.Movement, in triggerState.Static, PhysicsConstants.PhysicsStepTime / 1000f);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ internal BumperState CreateState()
DoUpdate = false,
EnableAnimation = true,
Rotation = new float2(0, 0),
Center = Position
Center = Position,
Duration = skirtAnimComponent.duration,
} : default;

// ring animation data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace VisualPinball.Unity
{
internal static class BumperRingAnimation
{
internal static void Update(ref BumperRingAnimationState state, float dTime)
internal static void Update(ref BumperRingAnimationState state, float dTimeMs)
{
// todo visibility - skip if invisible

Expand All @@ -33,7 +33,7 @@ internal static void Update(ref BumperRingAnimationState state, float dTime)
if (state.AnimateDown) {
step = -step;
}
state.Offset += step * dTime;
state.Offset += step * dTimeMs;
if (state.AnimateDown) {
if (state.Offset <= -limit) {
state.Offset = -limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BumperRingAnimationComponent : AnimationComponent<BumperData, Bumpe
#region Data

[Tooltip("How quick the ring moves down when the ball is hit.")]
public float RingSpeed = 0.5f;
public float RingSpeed = 1.0f;

[Tooltip("How low the ring drops. 0 = bottom")]
public float RingDropOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace VisualPinball.Unity
{
internal static class BumperSkirtAnimation
{
internal static void Update(ref BumperSkirtAnimationState state, float dTime)
internal static void Update(ref BumperSkirtAnimationState state, float dTimeMs)
{
// todo visibility - skip if invisible

Expand All @@ -34,8 +34,8 @@ internal static void Update(ref BumperSkirtAnimationState state, float dTime)
state.AnimationCounter = 0.0f;
}
if (state.DoAnimate) {
state.AnimationCounter += dTime;
if (state.AnimationCounter > 160.0f) {
state.AnimationCounter += dTimeMs;
if (state.AnimationCounter > state.Duration * 1000) {
state.DoAnimate = false;
ResetSkirt(ref state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ namespace VisualPinball.Unity
[AddComponentMenu("Visual Pinball/Animation/Bumper Skirt Animation")]
public class BumperSkirtAnimationComponent : AnimationComponent<BumperData, BumperComponent>
{
#region Data
[Tooltip("How long the skirt is pushed down when hit by a ball in seconds")]
public float duration = 0.1f;
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ internal struct BumperSkirtAnimationState

// static
public float2 Center;
public float Duration;
}
}