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!

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).

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.