So I'm making a game where the size of certain objects with rigidbodies is scalable. Unfortunately, there's nothing stopping me from upscaling them into a place where they won't fit. When that happens, Physics applies a penalty force to push them out of an intersection. I'd like to stop the scaling when that happens, but I've found no way to check it.
It seems like there should be a way to check if that penalty force has triggered in the last frame. Does anyone know how to access that or otherwise detect if two objects are intersecting (not just colliding)?
If I understand correctly, you just want the scaling to stop when it gets too big and like hits a wall or some collider/rigidbody, but still be able to go back down
I think you could use OnCollisionEnter or OnTriggerEnter. Basically, when it collides with something, save the current scale vector3 and enable the stopscaling portion of script in the update function, thus making it so the scale is locked at that maxScale vector3. When it exits (not colliding), it will disable the stopscaling script and allow scaling to resume.
Here is an example with OnCollisionEnter:
I haven't tested this script so there may be some bugs, but get back with me if it doesn't work. Good Luck.
answered Apr 17 '12 at 10:19 PM
If your collider is sphere or capsule there are methods to check intersection.
methods does that.
Or, maybe you can make rigidbody of your objects kinematic and scale them up until OnCollisionEnter method is triggered.