-
Notifications
You must be signed in to change notification settings - Fork 64
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
Make colliders fully transformable #500
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7e67bf4
to
f1d17a2
Compare
This reverts commit c2bc967.
This was referenced Jan 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces fully transformable colliders to the physics engine.
The key to transforming objects lies in how their transformations are stored. In VPX, due to its restrictions, transformations are generally stored as separate values. In Unity (and game engines in general), transformations are stored as matrices. Instead of converting between the transformations that the physics engine understands and the transformation matrix — and thereby restricting the editor's transformation tools to those limitations — we decided to rely exclusively on the transformation matrix. This approach allows complete freedom in transforming objects.
It also enables VPE to support parenting objects to others, allowing transformations of parent objects without disrupting the physics simulation.
So, how can the VPX physics code handle arbitrary transformations? The solution is a simple trick: rather than transforming the colliders, we transform the balls: To resolve a collision between a ball and a collider that is transformed in a non-supported way, we temporarily move the ball into the collider's local space, resolve the collision, and then return the ball to the playfield space.
Collider Data
Our colliders don't and won't know about our transformation matrices, i.e. the data used to calculate the simulation is still the same as in VPX. So, we need to get this data from the transformation matrices into the colliders. The chosen approach is the following:
Transform(float4x4)
method that transforms the collider in the playfield space. Transforming means updating the collider's position, rotation, and scale, whatever is supported. That's the data the VPX physics code uses.TransformAABBs(float4x4)
method that only transformsthe collider's axis-aligned bounding boxes, and that works for all transformations.
So, with all of the above, we do the following when the game starts:
of the item. We call it
LocalToPlayfieldMatrixInVpx
.LocalToPlayfieldMatrixInVpx
matrix.TransformAABBs(float4x4)
). Also note for kinematic colliders that aren't fully transformable, we'll fall back to this approach as well, because we don't know how the item will be transformed during runtime.This relatively simple approach gives us an incredible amount of flexibility. We now have a true 3D physics engine that can handle any kind of transformation, including parenting, while still being able to rely on the heuristics of the VPX physics code that has been tuned over the years.
Code Changes
Let's dive into the code. We'll need three more methods for each collider:
IsTransformable(float4x4)
: This method checks whether the collider can be transformed with the given matrix, i.e. if the physics code supports the transformation natively.Transform(float4x4)
: This method transforms the collider in VPX space.TransformAABBs(float4x4)
: This method transforms the collider's axis-aligned bounding boxes.In our
ColliderReference
class, we'll add afloat4x4
to eachAdd()
method. This method goes through the three use cases described above.IsTransformable(float4x4)
, it'll determine whether the collider can be transformed natively and usesTransform(float4x4)
if that's the case.IsTransformed
of the collider tofalse
. It also stores the transformation matrix so it can be used during runtime for the ball transformation trick.Note
For already fully transformable items like primitives, the above checks are not necessary, and we transform the collider with its AABBs directly without checking the actual transformation.
To summarize:
Other Changes
SpinnerLeverAnimation
for new spinner prefab.TODO
UpdateTransforms()
, there should only be minimal stuff in there.ITargetData
? It's pretty empty now...isLocked
, also go throughisEnabled
andisVisible
.float2.zero
from data components.