Exemplo n.º 1
0
    private void RotateSlerp(TurnPoints turnClass)
    {
        foreach (Transform rotPoint in turnClass.pointList)
        {
            //Relative aim point
            Vector2 targetDir = rotPoint.position - player.transform.position;

            //Target rotation is rotation it needs to have to aim directly at it
            Quaternion targetRotation = Quaternion.LookRotation(targetDir, Vector3.forward);
            targetRotation.x = 0;
            targetRotation.y = 0;

            Quaternion newRotation = targetRotation;

            //Current rotation
            Quaternion fromRotation = rotPoint.rotation;
            fromRotation.x = 0;
            fromRotation.y = 0;

            //Slerp rotation
            newRotation = Quaternion.Slerp(fromRotation, targetRotation, Time.deltaTime * turnClass.turnSpeed * Mathf.PI / 180);

            rotPoint.transform.rotation = newRotation;
        }
    }
Exemplo n.º 2
0
    //Instantly rotates toward target
    private void RotateInstant(TurnPoints turnClass)
    {
        foreach (Transform rotPoint in turnClass.pointList)
        {
            Vector2    targetDir   = rotPoint.position - player.transform.position;
            Quaternion newRotation = Quaternion.LookRotation(targetDir, Vector3.forward);
            newRotation.x = 0;
            newRotation.y = 0;

            rotPoint.rotation = newRotation;
        }
    }
Exemplo n.º 3
0
    private void RotateConstant(TurnPoints turnClass)
    {
        foreach (Transform rotPoint in turnClass.pointList)
        {
            //Relative aim point at player
            Vector2 targetDir = rotPoint.position - player.transform.position;

            //Target rotation is rotation it needs to have to aim directly at it
            Quaternion targetRotation = Quaternion.LookRotation(targetDir, Vector3.forward);
            //Makes sure that it rotates around the z axis
            targetRotation.x = 0;
            targetRotation.y = 0;

            Quaternion newRotation = targetRotation;

            //Current rotation
            Quaternion fromRotation = rotPoint.rotation;
            fromRotation.x = 0;
            fromRotation.y = 0;


            float targetRotZ  = targetRotation.eulerAngles.z;
            float currentRotZ = fromRotation.eulerAngles.z;


            //If same side (left or right)
            //Increase rotation
            if (targetRotZ >= currentRotZ &&
                ((targetRotZ >= 180 && currentRotZ >= 180) ||
                 (targetRotZ <= 180 && currentRotZ <= 180)))
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngle(currentRotZ, targetRotation.eulerAngles.z, 1, turnClass.turnSpeed));
            }

            //Decrease rotation
            else if (targetRotZ <= currentRotZ &&
                     ((targetRotZ >= 180 && currentRotZ >= 180) ||
                      (targetRotZ <= 180 && currentRotZ <= 180)))
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngle(currentRotZ, targetRotation.eulerAngles.z, -1, turnClass.turnSpeed));
            }


            //If from left side to right side
            //Increase rotation
            else if (targetRotZ <= currentRotZ + 180 &&
                     targetRotZ >= 180 && currentRotZ <= 180)
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngle(currentRotZ, targetRotation.eulerAngles.z, 1, turnClass.turnSpeed));
            }

            //Decrease rotation
            else if (targetRotZ >= currentRotZ + 180 &&
                     targetRotZ >= 180 && currentRotZ <= 180)
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngleSwitch(currentRotZ, targetRotation.eulerAngles.z, -1, turnClass.turnSpeed));
            }



            //If from right side to left side
            //Increase rotation
            else if (targetRotZ <= currentRotZ - 180 &&
                     targetRotZ <= 180 && currentRotZ >= 180)
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngleSwitch(currentRotZ, targetRotation.eulerAngles.z, 1, turnClass.turnSpeed));
            }

            //Decrease rotation
            else if (targetRotZ >= currentRotZ - 180 &&
                     targetRotZ <= 180 && currentRotZ >= 180)
            {
                newRotation.eulerAngles = new Vector3(0, 0, GetConstantAngle(currentRotZ, targetRotation.eulerAngles.z, -1, turnClass.turnSpeed));
            }

            //Set new rotation
            rotPoint.transform.rotation = newRotation;
        }
    }