Hi. I’m having a rather annoying problem with collision detection.It’s like this: I’m developing a game for iPad and I have a minigame where you’re supposed to drag some rectangles with your finger to get them in a correct position. The rectangles collide with eachother, in a sense that they cannot pass through each other. I’m using OnCollisionEnter to restrict movement of a rectangle when it hits another one. I’m moving the rectangles by manipulating their transform.position. Here is the problem. If I move the rectangles slow or moderatly fast, everything is OK, the collision is detected on time and restricts further movement. But if I swipe fast and thus moving the rectangle fast, OnCollisionEnter isn’t getting called on time, and the rectanglese overlap. I’ve tried using triggers, FixedUpdate instead of Update, no results. What can I possibly do to get OnCollisionEnter called on time? Any help would be appreciated, thanks
use rigidbodies instead or use a spherecast of roughly the side of the cube and project it ahead of the movement to check you aren’t going to pass through anything
Cant you move it with forces rather than manipulating transform.position and then set the collision type to continuous
I thought about using forces to move the object, but I’m not sure how to apply a discrete impulse to the object,so that it would look like a translation. If you could post a simple example it would be great.Thanx
Have you tried changing the Collision Detection on the Rigidbody to Continuous Dynamic?
That is designed to stop fast moving objects from passing through each other.
Yes, I tried that too
Rigidbody collisions don’t work at high speeds. Use Raycasting to achieve it. Rigidbodies are very broken on objects at high speeds… was a huge pain on a FPS I was making when I tried to make high speed bullets collide with characters, or even walls. To fix this, I shot out a bullet object with no collider for visual effect, and then raycasted to detect whether a character was hit or not.
I’m working on a game that will also use high speed objects that need advanced collision detection. Thanks for the tip on Raycasting
How exactly did you raycast? A simple example would help, thanx