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

How to rotate a collider #5

Open
dbramwell opened this issue May 13, 2019 · 2 comments
Open

How to rotate a collider #5

dbramwell opened this issue May 13, 2019 · 2 comments

Comments

@dbramwell
Copy link

I see that the rotate function can be applied to Polygons but not Colliders. If I create a crash.Box, what's the best way to rotate it?

@TuurDutoit
Copy link
Owner

Sorry for the slow response, I only see this now in my inbox...

As per the documentation for the Collider class, you can always reference the underlying SAT collider (Polygon or Circle) as collider.sat. Thus, collider.sat.rotate(angle) should work for you (though I haven't tested this myself).

@TuurDutoit
Copy link
Owner

As an addendum to my previous post:
After updating the underlying SAT collider object, two extra things need to be taken care of:

  1. the AABB (axis-aligned bounding box) of the Collider needs to be updated. This is required for rbush to be able to do what is does. You can use the Collider.updateAABB() method for this.
  2. the Collider must be added to the list of objects that have moved, in order to be checked for collisions in the next crash.check() call.

Note that both these actions are taken care of automatically when you use the Collider's built-in methods, like Polygon.rotate() for example. Isn't that the method you were looking for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants