How do I Update a Collider's Collison through script?
I have this problem where I have a 2DCircleCollider on my Character, and When you open something like a chest, Items inside the chest Appear by turning the gameObject Active from Inactive. Then, using the 2DCircleCollider around my character, it has the OnTriggerEnter2D function which adds objects within the radius into a list.
But! When an object is within the Radius, and then the Object turns active, it does not activate the OnTriggerEnter2D Function until I move my character in any direction, supposedly updating the fact that they are touching/overlapping.
So my question is, how can I make the OnTriggerEnter2D update the list without having to move my character after objects appear using the SetActive() function?
Answer by ZaddBuzuki · Jan 15, 2017 at 02:13 AM
I actually solved it: as well as making the object visible when the player opens the chest, it changes the position of what turns visible on the Z axis, so it is unoticable in 2D, and also moves it back the same amount on two lines of code.
item.localPosition += new Vector3(0,0,0.01f);
item.localPosition += new Vector3(0,0,-0.01f);
surprisingly, even doing this, and moving it back to its original position, updates it in the OnTriggerEnter2D, thus making everything run smoothly. Weird fix, but Nothing serious at all.
Your answer
Follow this Question
Related Questions
how to fire my player out of a Cannon? 0 Answers
How to add a jump key 2 Answers
Player making "random jumps" while is moving at random places (Unity 2D) 0 Answers
Any ideas in relate to a cube rolling? thank you! 0 Answers
Reduce Player Movement in Air 0 Answers