- Home /
How to check if rotating an object will cause a collision?
Suppose I've got a rigidbody made up of several colliders. When the player taps on the object, I want it to rotate only if there is space for it to rotate in it's current position, given that there might be walls or other rigidbodies nearby. Is there any way to check if the rotation will succeed before I actually move the object?
In the Unreal engine, there are functions like "SetLocation" and "SetRotation" which return a boolean value - true if the rotation succeeded, false if there was something in the way (and then the rotation does not occur). I guess I'm looking for similar functionality here if possible.
Thanks!
Answer by Chris D · Jun 02, 2011 at 09:41 PM
Similar to Anxo's suggestion, you could try having a "shadow" clone of the object you're checking. What I mean by that is either another instance of the object you're rotating or a simplified version but without a mesh renderer, only collider.
Once you have that, you could rotate the shadow version to where you want to check it and, if it doesn't collide, move the true object to match (and reset for the next check).
Answer by Anxo · Jun 02, 2011 at 08:39 PM
you could set empty game Objects in front of the object and have them shoot a ray, in the direction you are rotating, if they hit something within a specified distance, you could send a message back to let the object know thats its not cool to rotate.
Your answer
Follow this Question
Related Questions
Calculating Torque but cant add Quaternion 0 Answers
Rotating my character only while moving in a 2D plane 3 Answers
Tilt & Turn - Build stutter when turning 0 Answers
Rotating Camera, and Movement help. 1 Answer
Velocity based on rotation 1 Answer