- Home /
Getting size-dimensions from the other collider.
I have a script on cube #1. When cube #1 collides with cube #2, I need the script on the cube #1 to gather the size-dimensions of cube #2.
Like this:
Cube1 hits cube2.
Cube1 recieves "cube2's dimensions are 2, 3, 1".
Cube1 uses this information for something else.
Answer by aldonaletto · Jul 02, 2011 at 04:17 AM
If cube#2 is a trigger, you may use this in cube#1's script:
var otherScale: Vector3;
function OnTriggerEnter(col:Collider){
otherScale = col.transform.lossyScale;
}
If cube#2's is not a trigger, use OnCollisionEnter() instead:
function OnCollisionEnter(col:Collision){
otherScale = col.transform.lossyScale;
}
Anyway, the variable otherScale will have the world scale (lossyScale) of the last cube touched. For Unity's primitive cubes, it corresponds to their dimensions. It may not be true if the cubes are imported models.
Cube #1 can be a trigger, and there aren't actually any rigidbodies involved. Both are still.
Cube#1 may be a trigger, but you must add a rigidbody to it or to all other cubes - triggers and colliders only detect rigidbodies or character controllers. You can add a kinematic rigidbodoy to cube#1 (check Is $$anonymous$$inematic in the rigidbody) to avoid physics problems (cube#1 reacting to collisions).
Your answer
![](https://koobas.hobune.stream/wayback/20220612131233im_/https://answers.unity.com/themes/thub/images/avi.jpg)