void CollisionBR()
    {
        //====================================================================================================
        //line going to blue sphere first contact point
        a1 = sphere1B.transform.position - sphere2Coll.ClosestPointOnBounds(sphere1B.transform.position);
        a1.Normalize();
        Debug.DrawRay(sphere2R.transform.position, a1, Color.white);
        //line going to red sphere first contact point
        a2 = sphere2R.transform.position - sphere1Coll.ClosestPointOnBounds(sphere2R.transform.position);
        a2.Normalize();
        Debug.DrawRay(sphere1B.transform.position, a2, Color.white);
        //====================================================================================================
        //line going to blue sphere
        Vector3 n1 = sphere1B.transform.position - sphere2R.transform.position;

        n1.Normalize();
        Debug.DrawRay(sphere2R.transform.position + transform.up * 4, n1, Color.white);
        //line going to red sphere
        Vector3 n2 = sphere2R.transform.position - sphere1B.transform.position;

        n2.Normalize();
        Debug.DrawRay(sphere1B.transform.position + transform.up * 3, n2, Color.white);
        //====================================================================================================
        float a11 = Vector3.Dot(initialVelocityOfBlueSphere, n2);
        float a22 = Vector3.Dot(initialVelocityOfRedSphere, n1);
        //====================================================================================================

        double P = (2.0 * (a11 - a22)) / (massOfSphere1B + massOfSphere2R);

        //Vector3 v1AFTER = initialVelocityOfBlueSphere.x - P * massOfSphere2R * n1,initialVelocityOfBlueSphere.y - P * massOfSphere2R * n1 , initialVelocityOfBlueSphere.z - P * massOfSphere2R * n1);
        //current vel is going to be total then divide into 2
        //quantitiy a amount effected by coll
        //quant b prependicular to a will take all the collision
    }
Esempio n. 2
0
 private void ActivateExplosionEffectSmall()
 {
     if (explosionEffectObject != null)
     {
         Destroy(explosionEffectObject);
     }
     if (ExplosionEffectPrefab != null)
     {
         SphereCollider asteroidCollider = asteroidMain.GetComponent <SphereCollider>();
         if (asteroidCollider != null)
         {
             Vector3 placeOfExplosion = asteroidCollider.ClosestPointOnBounds(centerOfPlanet);
             explosionEffectObject = Instantiate(ExplosionEffectPrefab, placeOfExplosion, Quaternion.identity);
             explosionEffectObject.transform.localScale = Vector3.one * 0.3f;
         }
         else
         {
             Debug.LogWarning("There is no SphereCollider component on object " + asteroidMain.name);
         }
     }
     else
     {
         Debug.LogWarning("ExplosionEffectPrefab field is not assigned on object " + gameObject.name);
     }
 }
Esempio n. 3
0
        private void CreateSparkles(Collider other)
        {
            var closestPointOnSphere =
                _blackHoleSphere.ClosestPointOnBounds(other.transform.position + new Vector3(0, 0.5f, 0));
            var outSphereDirection = (closestPointOnSphere - _blackHoleSphere.transform.position).normalized;
            var sphereStartPoint   = closestPointOnSphere - outSphereDirection * _toInsideSphereCorrectiveFactor;

            GameObject.Instantiate(_blackHoleSparklesPrefab, sphereStartPoint, Quaternion.LookRotation(outSphereDirection));
        }