- Home /
Scaling colliders up and down over time
In my game, I have objects called "obstacles," which have a box collider and a rigidbody. The obstacles limit where the player can move in the levels. Sometimes these obstacles can move around the level, or rotate around. This is possible with Rigidbody2D.velocity and Rigidbody2D.angularVelocity, but here starts the problem.
I want to make the obstacles change in size throughout time, and Rigidbody2D's don't have a type of velocity for scales.
Now, currently I achieve this by changing transform.localScale, but, much like if you were to change position or rotation with transform.localPosition and transforrm.localEulerAngles, it can make the player phase through the collider.
If the obstacle scales up or down slowly enough, there's not really a problem here, since the player is automatically pushed out of the collider. The problem is that I have a trigger collider inside of the player object, which is just a bit smaller than its other collider, which is used to detect if the player is being crushed between two or more obstacles. The player phases through the resizing obstacle just enough for the trigger to activate, and this causes the game to detect a crush, even though there shouldn't be.
Is there any way to fix this?
Answer by NewDefectus · Nov 11, 2017 at 02:11 PM
I figured it out!
All I had to do was check the distance between the player and the center of the obstacle, then, if I detected that the player was touching the obstacle, multiply it by the resizing speed.
Your answer
Follow this Question
Related Questions
Moving colliders that are part of a composite collider 1 Answer
How to select the trigger layer on a Box Collider 2D 2 Answers
Rigidbody2D.velocity.x not working but Y does 0 Answers
Static Colliders in the 2D Engine in Unity 5 1 Answer
Making Rigidbodies to interact but allow them to go one through the other 1 Answer