Skip to content

Commit

Permalink
droptarget: Fix animation translation when rotated.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Nov 26, 2024
1 parent 3980449 commit d52a83e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions VisualPinball.Unity/VisualPinball.Unity/Game/PhysicsMovements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ internal void ApplyDropTargetMovement(ref NativeParallelHashMap<int, DropTargetS
while (enumerator.MoveNext()) {
ref var dropTargetState = ref enumerator.Current.Value;
var dropTargetTransform = transforms[dropTargetState.AnimatedItemId];
var localPos = dropTargetTransform.localPosition;
dropTargetTransform.localPosition = new Vector3(
localPos.x,
Physics.ScaleToWorld(dropTargetState.Animation.ZOffset),
localPos.z
);
var localYDirection = dropTargetTransform.up;

// Compute the new position by moving along the local Y-axis
var newPosition = (Vector3)dropTargetState.Static.InitialPosition + localYDirection * Physics.ScaleToWorld(dropTargetState.Animation.ZOffset);

// Apply the new position
dropTargetTransform.position = newPosition;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ internal DropTargetState CreateState()
Speed = animationComponent.Speed,
RaiseDelay = animationComponent.RaiseDelay,
UseHitEvent = colliderComponent.UseHitEvent,
InitialPosition = transform.position
} : default;

var animationData = colliderComponent && animationComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using Unity.Mathematics;

namespace VisualPinball.Unity
{
internal struct DropTargetStaticState
{
public float Speed;
public float RaiseDelay;
public bool UseHitEvent;
public float3 InitialPosition;
}
}

0 comments on commit d52a83e

Please sign in to comment.