Beispiel #1
0
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Disc")
     {
         GameObject    disc          = other.gameObject;
         Rigidbody     discRigidBody = disc.GetComponent <Rigidbody>();
         DiscBehaviour discBehaviour = disc.GetComponent <DiscBehaviour>();
         Vector3       newVelocity   = Vector3.Reflect(discRigidBody.velocity, -other.contacts[0].normal);
         if (newVelocity.magnitude < 5.0f)
         {
             newVelocity *= 3.0f;
         }
         discBehaviour.SetVelocity(newVelocity);
     }
 }
Beispiel #2
0
    private void Shot()
    {
        if (disc == null)
        {
            return;
        }

        DiscBehaviour discBehaviour = disc.gameObject.GetComponent <DiscBehaviour>();

        //rebound in coming direction with same power
        //discBehaviour.SetVelocity(-discBehaviour.GetVelocity());

        //rebound always forward with new power
        discBehaviour.SetVelocity(Body.forward * ReboundPower);

        isStopping    = false;
        stoppingTimer = StopTime;
        disc.transform.SetParent(stage.transform);
        disc = null;
    }
Beispiel #3
0
    private void Shot(Collision other)
    {
        DiscBehaviour disc            = other.gameObject.GetComponent <DiscBehaviour>();
        Transform     currentPosition = null;
        float         currentDistance = float.MaxValue;

        for (int i = 0; i < Positions.Length; i++)
        {
            float newDistance = (other.contacts[0].point - Positions[i].position).magnitude;

            if (newDistance < currentDistance)
            {
                currentDistance = newDistance;
                currentPosition = Positions[i];
            }
        }

        if (Player.IsShooting)
        {
            //----------new direction is the normal of the collision point
            //disc.SetVelocity(-other.contacts[0].normal * Power);
            //----------


            //----------new direction is scripted to eight points with cross method
            //if (Vector3.Cross(Player.transform.forward, currentPosition.position - Player.transform.position).y > 0.0f)
            //    disc.SetVelocity(currentPosition.forward * Power);
            //else
            //    disc.SetVelocity(-currentPosition.forward * Power);
            //----------


            //----------new direction is scripted to eight points with rotation method
            if (Player.RotationDirection > 0.0f)
            {
                disc.SetVelocity(currentPosition.forward * Power);
            }
            else
            {
                disc.SetVelocity(-currentPosition.forward * Power);
            }
            //----------
        }
        else
        {
            //----------new direction is the normal of the collision point
            //disc.SetVelocity((currentPosition.position - other.contacts[0].point).normalized * deflectionMul);
            //----------


            //----------new direction is scripted to eight points with cross method
            //if (Vector3.Cross(Player.transform.forward, currentPosition.position - Player.transform.position).y > 0.0f)
            //    disc.SetVelocity(currentPosition.forward * deflectionMul);
            //else
            //    disc.SetVelocity(-currentPosition.forward * deflectionMul);
            //----------


            //----------new direction is scripted to eight points with rotation method
            if (Player.RotationDirection > 0.0f)
            {
                disc.SetVelocity(currentPosition.forward * deflectionMul);
            }
            else
            {
                disc.SetVelocity(-currentPosition.forward * deflectionMul);
            }
            //----------
        }
    }