- Home /
change the scale of collider to trigger "OnTriggerEnter",Change the scale of collider to trigger "OnTriggerEnter"
Hi guys, Here is my question, I want to change the scale of a sphere collider to trigger other gameobjects (also with sphere colliders), but only few gameobjects trigger the "OnTriggerEnter".
I try to use script, to reset the scale value, or use dotween to DOScale it, or set the radius of collider, still the same, only few gameobjects trigger the "OnTriggerEnter".
I try to move the collider to touch other gameobjects. On mater use script or move in runtime, they are all work well.
So, dose anybody has the same problem like me? How can I scale a collider to trigger "OnTriggerEnter"?
For OnTrigger to work you must have:-
1) Collider attached to the gameobject
2) Script attached to the same gameobject
$$anonymous$$ake sure these are correct for all the objects you want to get triggered.
scale is the one thing that can't be expressed in any kind of velocity, so there's no smooth way to do this. if you do though, DOtween must run the scaling in FixedUpdate.
It might be a case where the scaling is done too quickly. This is always a problem with fast moving objects (and of course their colliders). The root cause is that collisions are calculated by the physics engine in one frame just before the "problem object", and then, when they are again calculated in the next frame, the collider has moved beyond the "problem object" so, it never actual touches the collider (being inside the sphere collider doesn't trigger).
You can check if this is the root cause, if you reduce the speed of scaling. If that's the cause, just google something like "Unity fast moving gameobjects colliders" or something similar. There are many topics on workarounds.
What u said is make scene for me, I made a test that doing scale really slow, but it still works bad.
A trigger collider will only be triggered by dynamic collders, that is ones that have a Rigidbody
on them, as seen in the table at the bottom of this page: https://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html
That is, your static colliders will not trigger it (makes sense if you think about it). $$anonymous$$oreover, if I remember correctly (but I haven't tested it), dynamic colliders that are not moving also do not trigger, because they are "asleep". This means that if an object has a Rigidbody, but its transform is not affected by anything (neither forces, nor velocity, nor directly setting position or rotation), then scaling the trigger will not detect that it entered the trigger.
Of cause I add the rigidbody, and it works well when I move it to touch other gameobject.
but its transform is not affected by anything (neither forces, nor velocity, nor directly setting position or rotation), then scaling the trigger will not detect that it entered the trigger.
Okey,
Thanks guys, I was using another way to solve this temporary, calculate the distance of the mian gameobject to others, and compare with the radius of sphere collider.
Your answer
Follow this Question
Related Questions
Register Particles going through Trigger collider 1 Answer
Check if something enters my trigget withowt OnTriggerEnter 1 Answer
Why doesn't this work? Comparing gameobjects in OnTriggerEnter 1 Answer
Disable Mesh Collider Trigger 1 Answer
Character collider falls away unless "isTrigger" selected 1 Answer