Example #1
0
    void Update()
    {
        AddPitchYaw(ref lookat, transform.position - CamTarget.GetTarget());

        if (player.GetComponent <Rigidbody>().velocity.magnitude > 1)
        {
            AddPitchYaw(ref target, -player.GetComponent <Rigidbody>().velocity);
        }

//		if(Input.GetMouseButton(0) && player.rigidbody.velocity.magnitude > 1)
//		{
//			velocityAngle += Input.GetAxis("Mouse X") * sensitivityX;
//
//			float spinVelocityDampen = 1-(angle * angle * SPIN_VELOSITY_DAMPEN_RATE * Time.deltaTime);
//
//
//			Vector3 TargetVel = Quaternion.Euler(0, angle, 0) *
//								player.rigidbody.velocity *
//								Mathf.Clamp01(spinVelocityDampen);
//
//			player.transform.LookAt(TargetVel);
//
//
//			player.rigidbody.velocity = Vector3.Lerp(player.rigidbody.velocity, TargetVel,0)



//			camInterp2 += mouse;
//
//			// in we spin 365 this makes it so it only spinns back 5
//			shrinkAngle(ref camInterp2);
//
//
//			camInterp1 = camInterp2;
//		}
        //else

        // camInterp1 interpolates towards 0 and camInterp2 interpolates towards camInterp1
        // provided they both start at the same place this gives camInterp2 a smooth acceleration and
        // deceleration
//			camInterp1 = Vector2.Lerp(camInterp1, Vector2.zero, CAM_RETURN_RATE * Time.deltaTime);
//			camInterp2 = Vector2.Lerp(camInterp2, camInterp1, CAM_RETURN_RATE * Time.deltaTime);


        Vector3 toLookatPos = transform.position - CamTarget.GetTarget();

        AddPitchYaw(ref lookat, toLookatPos);
        Vector2 midpointGase = Vector2.Lerp(target, lookat, CamTarget.sWeight);

        worldInterp = Vector2.Lerp(worldInterp, midpointGase, CamTarget.sRate * Time.deltaTime);



        transform.localEulerAngles = worldInterp;        // + camInterp2;

        //shrinkAngle(ref target);

        transform.position = player.transform.position;
    }
Example #2
0
    // Get the desired rotation.
    Quaternion CalculateDesiredRotation()
    {
        // The look at position quaternion
        Quaternion lookAtRot = Quaternion.LookRotation(CamTarget.GetTarget() - target.transform.position);

        // The rotation of the player.
        Quaternion forwardRot = Quaternion.LookRotation(target.transform.forward);

        // Use the variables in the trigger area to calculate the
        // desired rotation.
        Quaternion rot = Quaternion.Lerp(forwardRot, lookAtRot, CamTarget.sWeight);

        return(rot);
    }