Quantcast
Channel: Answers by "Matt-Downey"
Viewing all articles
Browse latest Browse all 90

Answer by Matt-Downey

$
0
0
I think you can add the following to OnCollisionEnter: var temp0 : Vector3; var temp1 : Vector3; var temp2 : Vector3; temp0 = collision.transform.position; temp1 = transform.position; //Step1 temp2 = temp1 - temp0; //Step2 temp2.Normalize(); //Step3 temp2 *= radius + radius; //or radius1 + radius2 //addition is faster than multiplication //not that it matters much for something so simple; //Step4 temp2 += temp0; transform.position = temp2; Basically, 1) take the position of the white ball and find the direction compared to the gray ball. 2) make the distance of this direction 1 meter long (if it's 10 meters away the distance will be one meter compared to the origin (0,0,0), perhaps something like (.707,0,.707) or (1,0,0). 3) multiply by the combined radii (if one ball were bigger with a radius or 2.5 and the others had a radius of .5 for instance, you would multiply by 3... 4) add this relative position to the actual position of the gray orb For step 4: the position of an object with respect to world space is the position relative to another object plus the distance of that other object with respect to world space.

Viewing all articles
Browse latest Browse all 90

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>