Пример #1
0
	void LateUpdate (){
		h = Input.GetAxis("RJHorizontal")*15f;				
		v = Input.GetAxis("RJVertical")*0.1f;
		leftX = Input.GetAxis("LJHorizontal");				
		leftY = Input.GetAxis("LJVertical");
		rjHText.text = h.ToString ();
		rjVText.text = v.ToString ();
		offset.y += v;
		offset.y = Mathf.Clamp (offset.y, -1f, 2f);
		Quaternion rotation = Quaternion.Euler (v, h, 0);

		if (Input.GetButtonDown("RJButton")) {
			if (camState == CamStates.Free && target != null) {
				camState = CamStates.Target;
				follow.Animator.SetBool ("Targeting", true);
				camStateText.text = "Target";
			} 
			else {
				camState = CamStates.Free;
				follow.Animator.SetBool ("Targeting", false);
				camStateText.text = "Free";
			}
		}
		Vector3 characterOffset = followXForm.position + offset;
		Vector3 negDistance = new Vector3(0.0f, 0.0f, -distanceAway);
		switch (camState) {
		case CamStates.Free:
			
			camSmoothDampTime = 0.1f;
			lookDir = characterOffset - this.transform.position;
			lookDir.y = 0;
			lookDir = rotation * lookDir;
			lookDir.Normalize ();
			targetPosition = characterOffset - lookDir * distanceAway;
			break;
		case CamStates.Target:
			camSmoothDampTime = 0.05f;
			Vector3 targetOffset = target.position;
			lookDir = targetOffset - this.transform.position;
			lookDir.y = 0;
			lookDir = rotation * lookDir;
			lookDir.Normalize ();

			targetPosition = characterOffset - lookDir * distanceAway;
			break;
		}
		CompensateForWalls (characterOffset, ref targetPosition);
		SmoothPosition(this.transform.position, targetPosition);
		transform.LookAt (followXForm);
		Debug.DrawRay (transform.position, lookDir, Color.red);
	}
Пример #2
0
    private void performNormalCameraMovement()
    {
        captureInputValues();
        calculateDesiredDistanceAwayBasedOnFollowers();
        Vector3 characterOffset = follow.position + new Vector3(0f, distanceUp, 0f);

        // Determine camera state
        if (Input.GetAxis("Jump") > 0.01f){
          //barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, widescreen, targetingTime);
          camState = CamStates.Target;
        } else if (rawHorizontalInputValue != 0f || (int)bankingCameraYDivisor != defaultBankingCameraYDivisor){
          camState = CamStates.Banking;
        } else {
          //barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, 0f, targetingTime);
          camState = CamStates.Behind;
        }

        switch(camState){
          case CamStates.Behind:
        // calculate direction from camera to player, kill y, and normalize to give a valid direction with unit magnitude
        lookDir = characterOffset - this.transform.position + (10 * follow.forward);
        //lookDir.y = 0;
        lookDir.y = lookDir.y / 2f;
        lookDir.Normalize();
        //Debug.DrawRay(this.transform.position, lookDir, Color.green);
        //Debug.DrawLine(follow.position, targetPosition, Color.magenta);
        break;
          case CamStates.Target:
        lookDir = follow.forward;
        break;
          case CamStates.Banking:
        calculateBankingDivisor();
        lookDir = follow.forward;
        lookDir.y = lookDir.y / bankingCameraYDivisor;
        lookDir.Normalize();
        break;
        }

        targetPosition = characterOffset + follow.up * distanceUp - lookDir * distanceAway;
        AdjustYValue(ref targetPosition);
        CompensateForWalls(characterOffset, ref targetPosition);
        smoothPosition(this.transform.position, targetPosition);
        transform.LookAt(follow);
    }
Пример #3
0
    void LateUpdate()
    {
        float mouseX = Input.GetAxis("Mouse X");
        float mouseY = Input.GetAxis("Mouse Y");

        Vector3 characterOffset = following.position + new Vector3(0f, distanceUp, 0f);

        Vector3 lookAt = characterOffset;

        //Determine camera state
        if (Input.GetAxis("Target") > TARGET_THRESHOLD)
        {
            camState = CamStates.Target;
        }
        else
        {


            if(Input.GetKeyDown(KeyCode.F))
            {
                fDown = !fDown;

                //first person
                if(!characterController.IsMoving() && !fDown)
                {
                    xAxisRotation = 0;
                    lookWeight = 0f;
                    camState = CamStates.FirstPerson;
                }

                if((camState == CamStates.FirstPerson && fDown) ||
                   (camState == CamStates.Target && (Input.GetAxis("Target") <= TARGET_THRESHOLD)))
                {
                    camState = CamStates.Behind;
                }
            }
        }

        //characterController.animator.SetLookAtWeight(lookWeight);

        switch (camState)
        {
            case CamStates.Behind:
                ResetCamera();
                lookDirection = characterOffset - this.transform.position;
                lookDirection.y = 0.0f;
                lookDirection.Normalize();
                targetPosition = characterOffset + following.up * distanceUp - lookDirection * distanceAway;
                break;
            case CamStates.Target:
                ResetCamera();
                lookDirection = following.forward;
                targetPosition = characterOffset + following.up * distanceUp - lookDirection * distanceAway;
                camState = CamStates.Behind;
                break;
            case CamStates.FirstPerson:

                //Calculate amount of rotation and apply to firstPersonCameraPosition
                xAxisRotation += (mouseY * 0.5f * firstPersonLookSpeed);
                xAxisRotation = Mathf.Clamp(xAxisRotation, firstPersonXAxisClamp.x, firstPersonXAxisClamp.y);
                firstPersonCameraPosition.Transform.localRotation = Quaternion.Euler(-xAxisRotation, 0f, 0f);

                //superimpose firstPersonCameraPosition rotation on camera
                Quaternion rotationShift = Quaternion.FromToRotation(this.transform.forward, firstPersonCameraPosition.Transform.forward);
                this.transform.rotation = rotationShift * this.transform.rotation;

                //Optional animation can go here
                //such as moving the character's while looking around

                //look left and right
                Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, fpRotationDegPerSec * (mouseX < 0f ? -1f : 1f), 0f), Mathf.Abs(mouseX));
                Quaternion xRotation = Quaternion.Euler(rotationAmount * Time.deltaTime);
                characterController.transform.rotation = (characterController.transform.rotation * xRotation);

                //Move camera
                targetPosition = firstPersonCameraPosition.Transform.position;

                lookAt = Vector3.Lerp(targetPosition + following.forward, this.transform.position + this.transform.forward, camSmoothDampTime * Time.deltaTime);

                //choose target based on distance
                lookAt = (Vector3.Lerp(this.transform.position + this.transform.forward, lookAt, 
                          Vector3.Distance(this.transform.position, firstPersonCameraPosition.Transform.position)));
                break;
        }

        wallDetection(characterOffset, ref targetPosition);
        smoothPosition(this.transform.position, targetPosition);
        transform.LookAt(lookAt);
    }
    void FixedUpdate()
    {
        // Pull values from controller/keyboard
        float rightX = Input.GetAxis("RightStickX");
        float rightY = Input.GetAxis("RightStickY");
        float leftX = Input.GetAxis("Horizontal");
        float leftY = Input.GetAxis("Vertical");

        Vector3 characterOffset = followXform.position + new Vector3(0f, distanceUp, 0f);

        Vector3 targetPosition = Vector3.zero;

        // Determine camera state
        // * Targeting *
        if (Input.GetAxis("Target") > TARGETING_THRESHOLD)
        {
            // Target Mode!!
            camState = CamStates.Target;
        }
        else
        {
            // * Free *
            //			if (rightY < freeThreshold && System.Math.Round(follow.Speed, 2) == 0)
            //			{
            //				camState = CamStates.Free;
            //				savedRigToGoal = Vector3.zero;
            //			}
            //			// * Behind the back *
            //			if ((camState == CamStates.FirstPerson) ||
            //			    (camState == CamStates.Target && (Input.GetAxis("Target") <= TARGETING_THRESHOLD)))
            //			{
            //				camState = CamStates.Behind;
            //			}
            camState = CamStates.Free;
        }

        // Set the Look At Weight - amount to use look at IK vs using the head's animation
        Debug.Log(camState);
        switch (camState)
        {
        case CamStates.Behind:
            ResetCamera();

            // Reset lookAt in case we were just in targetting mode
            lookAt = characterOffset;

            // Only update camera look direction if moving
            //if (anim.Speed > follow.LocomotionThreshold && follow.IsInLocomotion() && !follow.IsInPivot())
            //{
            lookDir = Vector3.Lerp(followXform.right * (leftX < 0 ? 1f : -1f), followXform.forward * (leftY < 0 ? -1f : 1f), Mathf.Abs(Vector3.Dot(this.transform.forward, followXform.forward)));
            Debug.DrawRay(this.transform.position, lookDir, Color.white);

            // Calculate direction from camera to player, kill Y, and normalize to give a valid direction with unit magnitude
            curLookDir = Vector3.Normalize(characterOffset - this.transform.position);
            curLookDir.y = 0;
            Debug.DrawRay(this.transform.position, curLookDir, Color.green);

            // Damping makes it so we don't update targetPosition while pivoting; camera shouldn't rotate around player
            curLookDir = Vector3.SmoothDamp(curLookDir, lookDir, ref velocityLookDir, lookDirDampTime);
            //}

            targetPosition = characterOffset + followXform.up * distanceUp - Vector3.Normalize(curLookDir) * distanceAway;
            Debug.DrawLine(followXform.position, targetPosition, Color.magenta);

            lookAt = characterOffset;
            break;
        case CamStates.Target:
            ResetCamera();
            lookDir = followXform.forward;
            curLookDir = followXform.forward;

            targetPosition = characterOffset + followXform.up * distanceUp - lookDir * distanceAway;

            break;
        case CamStates.Free:

            // Reset lookat in case we were just in targetting mode
            lookAt = characterOffset;

            lookWeight = Mathf.Lerp(lookWeight, 0.0f, Time.deltaTime * firstPersonLookSpeed);

            // Move height and distance from character in separate parentRig transform since RotateAround has control of both position and rotation
            Vector3 rigToGoalDirection = Vector3.Normalize(characterOffset - this.transform.position);
            // Can't calculate distanceAway from a vector with Y axis rotation in it; zero it out
            rigToGoalDirection.y = 0f;

            Vector3 rigToGoal = characterOffset - parentRig.position;
            rigToGoal.y = 0;
            Debug.DrawRay(parentRig.transform.position, rigToGoal, Color.red);

            // Panning in and out
            // If statement works for positive values; don't tween if stick not increasing in either direction; also don't tween if user is rotating
            // Checked against rightStickThreshold because very small values for rightY mess up the Lerp function
            if (rightY < -1f * rightStickThreshold && rightY <= rightStickPrevFrame.y && Mathf.Abs(rightX) < rightStickThreshold)
            {
                distanceUpFree = Mathf.Lerp(distanceUp, distanceUp * distanceUpMultiplier, Mathf.Abs(rightY));
                distanceAwayFree = Mathf.Lerp(distanceAway, distanceAway * distanceAwayMultipler, Mathf.Abs(rightY));
                targetPosition = characterOffset + followXform.up * distanceUpFree - rigToGoalDirection * distanceAwayFree;
            }
            else if (rightY > rightStickThreshold && rightY >= rightStickPrevFrame.y && Mathf.Abs(rightX) < rightStickThreshold)
            {
                // Subtract height of camera from height of player to find Y distance
                distanceUpFree = Mathf.Lerp(Mathf.Abs(transform.position.y - characterOffset.y), camMinDistFromChar.y, rightY);
                // Use magnitude function to find X distance
                distanceAwayFree = Mathf.Lerp(rigToGoal.magnitude, camMinDistFromChar.x, rightY);

                targetPosition = characterOffset + followXform.up * distanceUpFree - rigToGoalDirection * distanceAwayFree;
            }

            // Store direction only if right stick inactive
            if (rightX != 0 || rightY != 0)
            {
                savedRigToGoal = rigToGoalDirection;
            }

            // Rotating around character
            parentRig.RotateAround(characterOffset, followXform.up, freeRotationDegreePerSecond * (Mathf.Abs(rightX) > rightStickThreshold ? rightX : 0f));

            // Still need to track camera behind player even if they aren't using the right stick; achieve this by saving distanceAwayFree every frame
            if (targetPosition == Vector3.zero)
            {
                targetPosition = characterOffset + followXform.up * distanceUpFree - savedRigToGoal * distanceAwayFree;
            }

            //                                SmoothPosition(transform.position, targetPosition);
            //                                transform.LookAt(lookAt);
            break;
        }

        //                if (camState != CamStates.Free)
        //                {
        CompensateForWalls(characterOffset, ref targetPosition);

        SmoothPosition(parentRig.position, targetPosition);

        transform.LookAt(lookAt);
        //                }

        rightStickPrevFrame = new Vector2(rightX, rightY);
    }
Пример #5
0
	public void ToFocusFirst ()
	{
		//follow = t.GetComponent<CharacterControllerLogic> ();
	
		camState = CamStates.FirstPerson;
	}
Пример #6
0
		public void ToFocusBuilding (Transform t)
		{
				//follow = t.GetComponent<CharacterControllerLogic> ();
				followXform = t;
				camState = CamStates.AutoSurround;
		}
Пример #7
0
		//start to trigger this
		public void BrowseMode ()
		{
				camState = CamStates.Browse; 
				camera.rotation = Quaternion.Euler (new Vector3 (start_angle.x, start_angle.y, 0f));
				target_cam_pos = oPos;
				setTouch (true);
		}
	/// <summary>
	/// Use this for initialization.
	/// </summary>
	void Start ()
	{
		cameraXform = this.transform;//.parent;
		if (cameraXform == null)
		{
			Debug.LogError("Parent camera to empty GameObject.", this);
		}
		
		follow = GameObject.FindWithTag("Player").GetComponent<CharacterControllerLogic>();
		followXform = GameObject.FindWithTag("Player").transform;
		
		lookDir = followXform.forward;
		curLookDir = followXform.forward;
		
		barEffect = GetComponent<BarsEffect>();
		if (barEffect == null)
		{
			Debug.LogError("Attach a widescreen BarsEffect script to the camera.", this);
		}
		
		// Position and parent a GameObject where first person view should be
		firstPersonCamPos = new CameraPosition();
		firstPersonCamPos.Init
			(
				"First Person Camera",
				new Vector3(0.0f, 1.6f, 0.2f),
				new GameObject().transform,
				follow.transform
			);	

		camState = startingState;

		// Intialize values to avoid having 0s
		characterOffset = followXform.position + new Vector3(0f, distanceUp, 0f);
		distanceUpFree = distanceUp;
		distanceAwayFree = distanceAway;
		savedRigToGoal = RigToGoalDirection;
	}
Пример #9
0
		void LateUpdate ()
		{		

				if (follow == null || followXform == null) {
						return;
				}

				// Pull values from controller/keyboard
				float rightX = 0f;
				//Input.GetAxis("RightStickX");
				float rightY = 0f;//Input.GetAxis("RightStickY");
				float leftX = 0f;//Input.GetAxis("Horizontal");
				float leftY = 0f;//Input.GetAxis("Vertical");	
		
				Vector3 characterOffset = followXform.position + new Vector3 (0f, distanceUp, 0f);
				Vector3 lookAt = characterOffset;
				Vector3 targetPosition = Vector3.zero;
		
				// Determine camera state
				// * Targeting *
				//isTargeted
				//if (Input.GetAxis ("Target") > TARGETING_THRESHOLD) {
				if (isTargeted) {
						barEffect.coverage = Mathf.SmoothStep (barEffect.coverage, widescreen, targetingTime);
						camState = CamStates.Target;
				} else {			
						barEffect.coverage = Mathf.SmoothStep (barEffect.coverage, 0f, targetingTime);
			
						// * First Person *
						if (rightY > firstPersonThreshold && camState != CamStates.Free && camState != CamStates.Free && !follow.IsInLocomotion ()) {
								// Reset look before entering the first person mode
								xAxisRot = 0;
								lookWeight = 0f;
								camState = CamStates.FirstPerson;
						}
						if (rightY < freeThreshold && System.Math.Round (follow.Speed, 2) == 0) {
								camState = CamStates.Free;
								savedRigToGoal = Vector3.zero;
						}
						// * Behind the back *
						//
						if ((camState == CamStates.FirstPerson && exit_fpv) || (camState == CamStates.Target && !isTargeted)) {
								camState = CamStates.Behind;	
						}
				}
		
				// Set the Look At Weight - amount to use look at IK vs using the head's animation
				//follow.Animator.SetLookAtWeight (lookWeight);
		
				// Execute camera state
				switch (camState) {
				case CamStates.Behind:
						ResetCamera ();
			
			// Only update camera look direction if moving
						if (follow.Speed > follow.LocomotionThreshold && follow.IsInLocomotion () && !follow.IsInPivot ()) {
								lookDir = Vector3.Lerp (followXform.right * (leftX < 0 ? 1f : -1f), followXform.forward * (leftY < 0 ? -1f : 1f), Mathf.Abs (Vector3.Dot (this.transform.forward, followXform.forward)));
								Debug.DrawRay (this.transform.position, lookDir, Color.white);
				
								// Calculate direction from camera to player, kill Y, and normalize to give a valid direction with unit magnitude
								curLookDir = Vector3.Normalize (characterOffset - this.transform.position);
								curLookDir.y = 0;
								Debug.DrawRay (this.transform.position, curLookDir, Color.green);
				
								// Damping makes it so we don't update targetPosition while pivoting; camera shouldn't rotate around player
								curLookDir = Vector3.SmoothDamp (curLookDir, lookDir, ref velocityLookDir, lookDirDampTime);
						}				
			
						targetPosition = characterOffset + followXform.up * distanceUp - Vector3.Normalize (curLookDir) * distanceAway;
						Debug.DrawLine (followXform.position, targetPosition, Color.gray);
			
						break;
				case CamStates.Target:
						ResetCamera ();
						lookDir = followXform.forward;
						curLookDir = followXform.forward;
						targetPosition = characterOffset + followXform.up * distanceUp - lookDir * distanceAway;
			
						break;
				case CamStates.AutoSurround:
						ResetCamera ();
						//lookDir = followXform.forward;
						//xAxisRot += (leftY * 0.5f * firstPersonLookSpeed)
						//lookDir = followXform.forward;
						//curLookDir = followXform.forward;
						surroundingm += surroundSpeed;
						targetPosition = followXform.position + surroundDisUp * (1 + 1 / distanceUpMultiplier) * Vector3.up + Quaternion.Euler (0f, surroundingm, 0f) * followXform.forward * distanceAway;
						lookAt = followXform.position + distanceUp * Vector3.up;
						Debug.DrawLine (followXform.position, targetPosition, Color.white);
						break;	
				case CamStates.FirstPerson:	
			// Looking up and down
			// Calculate the amount of rotation and apply to the firstPersonCamPos GameObject
						xAxisRot += (leftY * 0.5f * firstPersonLookSpeed);			
						xAxisRot = Mathf.Clamp (xAxisRot, firstPersonXAxisClamp.x, firstPersonXAxisClamp.y); 
						firstPersonCamPos.XForm.localRotation = Quaternion.Euler (xAxisRot, 0, 0);
			
			// Superimpose firstPersonCamPos GameObject's rotation on camera
						Quaternion rotationShift = Quaternion.FromToRotation (this.transform.forward, firstPersonCamPos.XForm.forward);		
						this.transform.rotation = rotationShift * this.transform.rotation;		
			
			// Move character model's head
						//follow.Animator.SetLookAtPosition (firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward);
						//lookWeight = Mathf.Lerp (lookWeight, 1.0f, Time.deltaTime * firstPersonLookSpeed);
			
			
			// Looking left and right
			// Similarly to how character is rotated while in locomotion, use Quaternion * to add rotation to character
						//Vector3 rotationAmount = Vector3.Lerp (Vector3.zero, new Vector3 (0f, fPSRotationDegreePerSecond * (leftX < 0f ? -1f : 1f), 0f), Mathf.Abs (leftX));
						//Quaternion deltaRotation = Quaternion.Euler (rotationAmount * Time.deltaTime);
						//follow.transform.rotation = (follow.transform.rotation * deltaRotation);
			
			// Move camera to firstPersonCamPos
						targetPosition = firstPersonCamPos.XForm.position;
			
			// Smoothly transition look direction towards firstPersonCamPos when entering first person mode
						lookAt = Vector3.Lerp (targetPosition + followXform.forward, this.transform.position + this.transform.forward, camSmoothDampTime * Time.deltaTime);
						Debug.DrawRay (Vector3.zero, lookAt, Color.black);
						Debug.DrawRay (Vector3.zero, targetPosition + followXform.forward, Color.white);	
						Debug.DrawRay (Vector3.zero, firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward, Color.cyan);
			
			// Choose lookAt target based on distance
						lookAt = (Vector3.Lerp (this.transform.position + this.transform.forward, lookAt, Vector3.Distance (this.transform.position, firstPersonCamPos.XForm.position)));
						break;
				case CamStates.Free:
						lookWeight = Mathf.Lerp (lookWeight, 0.0f, Time.deltaTime * firstPersonLookSpeed);
			
			// Move height and distance from character in separate parentRig transform since RotateAround has control of both position and rotation
						Vector3 rigToGoalDirection = Vector3.Normalize (characterOffset - this.transform.position);
			// Can't calculate distanceAway from a vector with Y axis rotation in it; zero it out
						rigToGoalDirection.y = 0f;
			
						Vector3 rigToGoal = characterOffset - parentRig.position;
						rigToGoal.y = 0;
						Debug.DrawRay (parentRig.transform.position, rigToGoal, Color.red);
			
			// Panning in and out
			// If statement works for positive values; don't tween if stick not increasing in either direction; also don't tween if user is rotating
			// Checked against rightStickThreshold because very small values for rightY mess up the Lerp function
						if (rightY < -1f * rightStickThreshold && rightY <= rightStickPrevFrame.y && Mathf.Abs (rightX) < rightStickThreshold) {
								distanceUpFree = Mathf.Lerp (distanceUp, distanceUp * distanceUpMultiplier, Mathf.Abs (rightY));
								distanceAwayFree = Mathf.Lerp (distanceAway, distanceAway * distanceAwayMultipler, Mathf.Abs (rightY));
								targetPosition = characterOffset + followXform.up * distanceUpFree - rigToGoalDirection * distanceAwayFree;
						} else if (rightY > rightStickThreshold && rightY >= rightStickPrevFrame.y && Mathf.Abs (rightX) < rightStickThreshold) {
								// Subtract height of camera from height of player to find Y distance
								distanceUpFree = Mathf.Lerp (Mathf.Abs (transform.position.y - characterOffset.y), camMinDistFromChar.y, rightY);
								// Use magnitude function to find X distance	
								distanceAwayFree = Mathf.Lerp (rigToGoal.magnitude, camMinDistFromChar.x, rightY);
				
								targetPosition = characterOffset + followXform.up * distanceUpFree - rigToGoalDirection * distanceAwayFree;
						}
			
			// Store direction only if right stick inactive
						if (rightX != 0 || rightY != 0) {
								savedRigToGoal = rigToGoalDirection;
						}
			
			
			// Rotating around character
						parentRig.RotateAround (characterOffset, followXform.up, freeRotationDegreePerSecond * (Mathf.Abs (rightX) > rightStickThreshold ? rightX : 0f));
			
			// Still need to track camera behind player even if they aren't using the right stick; achieve this by saving distanceAwayFree every frame
						if (targetPosition == Vector3.zero) {
								targetPosition = characterOffset + followXform.up * distanceUpFree - savedRigToGoal * distanceAwayFree;
						}
			
			//				SmoothPosition(transform.position, targetPosition);
			//				transform.LookAt(lookAt);	
						break;
				}
		
		
				//if (camState != CamStates.Free) {
				CompensateForWalls (characterOffset, ref targetPosition);
				SmoothPosition (parentRig.position, targetPosition);
				transform.LookAt (lookAt);	
				//}
		
				rightStickPrevFrame = new Vector2 (rightX, rightY);
		}
Пример #10
0
    /// <summary>
    /// Use this for initialization.
    /// </summary>
    void Start()
    {
        initPosition();

        parentRig = this.transform.parent;
        if (parentRig == null)
        {
            Debug.LogError("Parent camera to empty GameObject.", this);
        }

        lookDir = followXform.forward;
        curLookDir = followXform.forward;

        camState = CamStates.Free;
        ResetCamera();
    }
    void LateUpdate()
    {
        //Debug.Log(follow.Speed);
        float rightX = Input.GetAxis("RightStickX");
        float rightY = Input.GetAxis("RightStickY");
        float leftX = Input.GetAxis("Horizontal");
        float leftY = Input.GetAxis("Vertical");

        //Debug.Log(Input.GetAxis("Triggers"));
        //Vector3 characterOffset = followTarget.position + offset;
        Vector3 characterOffset = followTarget.position + new Vector3(0f,height, 0f);
        Vector3 lookAt = characterOffset;

        if(Input.GetAxis("Triggers")>targettingThreshold){
            //barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, widescreen, targetingTime);
            camState = CamStates.Target;
        }else{
        //barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, 0.0f, targetingTime);
            if(rightY > firstPersonThreshold && /*camState != CamStates.Free &&*/ !follow.IsInLocomotion()){
                xAxisRot = 0;
                lookWeight = 0f;
                camState = CamStates.FirstPerson;
            }
            if((camState == CamStates.FirstPerson && Input.GetButton("BButton")) ||
               (camState == CamStates.Target && (Input.GetAxis("Triggers")<=targettingThreshold))){

            camState = CamStates.Behind;
            }
        }
        follow.Animator.SetLookAtWeight(lookWeight);
        switch(camState){
        case CamStates.Behind:
            ResetCamera();
            if(follow.Speed >follow.LocomotionThreshold && follow.IsInLocomotion() && !follow.IsInPivot()){
                lookDir = Vector3.Lerp(followTarget.right * (leftX < 0 ? 1f : -1f), followTarget.forward * (leftY < 0 ? -1f : 1f), Mathf.Abs(Vector3.Dot(this.transform.forward,followTarget.forward)));
                Debug.DrawRay(this.transform.position, lookDir, Color.white);

                //Calculate direction from camera to player, kill Y, and normalize to give a valid direction with unit magnitude
                curLookDir = Vector3.Normalize(characterOffset - this.transform.position);
                curLookDir.y = 0;
                Debug.DrawRay(this.transform.position, curLookDir, Color.green);
                //Damping makes it so we don't update target position while pivoting; camera shouldn't rotate around player
                curLookDir = Vector3.SmoothDamp(curLookDir, lookDir, ref velocityLookDir, lookDirDampTime);

            }
        //			targetPosition = characterOffset + followTarget.up * height - lookDir * distance;
            targetPosition = characterOffset + followTarget.up * height - Vector3.Normalize(curLookDir) * distance;
        //	Debug.DrawRay(followTarget.position, followTarget.up *height, Color.red);
        //	Debug.DrawRay(followTarget.position, -1f * followTarget.forward * distance, Color.blue);
            Debug.DrawLine(followTarget.position, targetPosition, Color.magenta);

            break;
        case CamStates.Target:

            ResetCamera();
        //			fadeTexture.Resize(1,1);
            lookDir = followTarget.forward;
            curLookDir = lookDir;
            targetPosition = characterOffset + followTarget.up * height - lookDir *distance;
            //this.transform.position = targetPosition;
            break;
        case CamStates.FirstPerson:
            //Calculate the amount of Rotation to firstPersonCamPos
            xAxisRot += (leftY * firstPersonLookSpeed);
            xAxisRot = Mathf.Clamp(xAxisRot, firstPersonXAxisClamp.x, firstPersonXAxisClamp.y);
            firstPersonCamPos.XForm.localRotation = Quaternion.Euler(xAxisRot, 0, 0);

            //Superimpose firstPersonCamPos rotation onto camera
            Quaternion rotationShift = Quaternion.FromToRotation(this.transform.forward, firstPersonCamPos.XForm.forward);
            this.transform.rotation = rotationShift * this.transform.rotation;

            //Choose lookAt target based on distance

            follow.Animator.SetLookAtPosition(firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward);
            lookWeight = Mathf.Lerp (lookWeight, 1.0f, Time.deltaTime * firstPersonLookSpeed);

            Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, fPSRotationDegreePerSecond * (leftX <0f ? -1f : 1f), 0f), Mathf.Abs(leftX));
            Quaternion deltaRotation = Quaternion.Euler(rotationAmount *Time.deltaTime);
            follow.transform.rotation = (follow.transform.rotation * deltaRotation);

            targetPosition = firstPersonCamPos.XForm.position;

            lookAt = Vector3.Lerp(targetPosition + followTarget.forward, this.transform.forward, camSmoothDampTime * Time.deltaTime);

            lookAt = (Vector3.Lerp(this.transform.position + this.transform.forward, lookAt, Vector3.Distance(this.transform.position, firstPersonCamPos.XForm.position)));
            break;
        }

        WallCollision(characterOffset, ref targetPosition);
        smoothPosition(this.transform.position, targetPosition);
        transform.LookAt(lookAt);
    }
Пример #12
0
    void LateUpdate()
    {
        //A distance away from the character
        Vector3 characterOffset = followXForm.position + new Vector3(0f, distanceUp, 0f);

        //determine camera state
        if(Input.GetAxis("Target") > 0.01f)
        {
            barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, wideScreen, targetingTime);

            camState = CamStates.Target;
        }
        else
        {
            barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, 0f, targetingTime);

            camState = CamStates.Behind;
        }

        switch(camState)
        {
            case CamStates.Behind:
                //calculate direction of the camera in relation to the player
                lookDir = characterOffset - this.transform.position;
                //vector from the head of the character to the camera
                lookDir.y = 0;
                lookDir.Normalize();
                //kill the y value and normalize and this gives us the direction
                Debug.DrawRay (this.transform.position, lookDir, Color.green);

                //setting the position of the camera be doing vector addition
                targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
                Debug.DrawRay (followXForm.position, Vector3.up * distanceUp, Color.red);
                Debug.DrawRay (followXForm.position, -1f * followXForm.forward * distanceAway, Color.blue);
                Debug.DrawLine (followXForm.position, targetPosition, Color.magenta);
                //targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
            break;

            case CamStates.Target:
                lookDir = followXForm.forward;

            break;
        }
        targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
        CompensateForWalls (characterOffset, ref targetPosition);

        smoothPosition(this.transform.position, targetPosition);
        //targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;

        //camera faces the character
        transform.LookAt (followXForm);
    }
	// Late update is useful for camera stuff because it will happen after you've positioned all your objects.
	void LateUpdate()
	{
		// Pull valuesfrom controller/keyboard
		float rightX = Input.GetAxis("RightStickX");
		float rightY = Input.GetAxis("RightStickY"); 
		float leftX = Input.GetAxis("Horizontal");
		float leftY = Input.GetAxis("Vertical");
		Vector3 characterOffset = followXForm.position + new Vector3(0f, distanceUp, 0f);
		Vector3 lookAt = characterOffset;

		// Determine camera state
		if(Input.GetAxis("Target") > TARGETING_THRESHOLD)
		{
			barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, widescreen, targetingTime);

			camState = CamStates.Target;
		}
		else
		{
			barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, 0f, targetingTime);

			// * First Person *
			if(rightY > firstPersonThreshold && !follow.IsInLocomotion())
			{
				// Reset look before entering the first person mode
				xAxisRot = 0;
				lookWeight = 0f;
				camState = CamStates.FirstPerson;
			}

			// *Behind the Back *
			if((camState == CamStates.FirstPerson && Input.GetButton("ExitFPV")) ||
				(camState == CamStates.Target && (Input.GetAxis("Target") <= TARGETING_THRESHOLD)))
			{
				camState = CamStates.Behind;
			}

		}

		// Get the Look At Weight - amount to use look at IK vs using the head's animation
		follow.Animator.SetLookAtWeight(lookWeight);

		// Execute Camera State
		switch(camState)
		{
			case CamStates.Behind:
				ResetCamera();	
				// Calculate direction from camera to player, kill Y, and normalize to give a valid direction with unity magnitude.
				lookDir = characterOffset - this.transform.position;
				lookDir.y = 0;
				lookDir.Normalize();
				Debug.DrawRay(this.transform.position, lookDir, Color.green);

				targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
				Debug.DrawLine(followXForm.position, targetPosition, Color.magenta);
				break;
			case CamStates.Target:
				ResetCamera();
				lookDir = followXForm.forward;
				targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
				break;
			case CamStates.FirstPerson:
				// Looking up and down
				// Calculate the amount of rotation and apply to the firstPersonCamPos GameObject
				xAxisRot += (leftY * firstPersonLookSpeed);
				xAxisRot = Mathf.Clamp(xAxisRot, firstPersonXAxisClamp.x, firstPersonXAxisClamp.y);
				firstPersonCamPos.XForm.localRotation = Quaternion.Euler(xAxisRot, 0, 0);
				
				// Superimpose firstPersonCam's Game Object on camera
				Quaternion rotationShift = Quaternion.FromToRotation(this.transform.forward, firstPersonCamPos.XForm.forward);
				this.transform.rotation = rotationShift * this.transform.rotation;

				// Mover character's Head
				follow.Animator.SetLookAtPosition(firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward);
				lookWeight = Mathf.Lerp (lookWeight, 1.0f, Time.deltaTime * firstPersonLookSpeed);

				// Looking Left and Right
				// Similarily to how character is rotated while in locomotion, use Quaternion + to add rotation to character
				// INFO: Lerp doesn't work with negitive values, so use .Abs (which makes all values positive to my knowledge)

				Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, fPSRotationDegreePerSecond * (leftX < 0f ? -1f : 1f), 0f), Mathf.Abs(leftX));
				Quaternion deltaRotation = Quaternion.Euler(rotationAmount * Time.deltaTime);
				follow.transform.rotation = (follow.transform.rotation * deltaRotation);

				// Move camera to firstPersonCamPos
				targetPosition = firstPersonCamPos.XForm.position;

				// Smoothy transform look direciton towards firstPersonCamPos when entering first person mode.
				lookAt = Vector3.Lerp(targetPosition + followXForm.forward, this.transform.position + this.transform.forward, camSmoothDampTime * Time.deltaTime);
				Debug.DrawRay(Vector3.zero, lookAt, Color.black);
				Debug.DrawRay(Vector3.zero, targetPosition + followXForm.forward, Color.white);
				Debug.DrawRay(Vector3.zero, firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward, Color.cyan);


				// Choose lookAt target based on distance
				lookAt = Vector3.Lerp (this.transform.position + this.transform.forward, lookAt, Vector3.Distance(this.transform.position, firstPersonCamPos.XForm.position));
				break;
		}



		CompensateForWalls(characterOffset, ref targetPosition);
		smoothPosition(this.transform.position, targetPosition);

		// Make sure the camera is looking the right way!
		transform.LookAt(lookAt);
	}
    void LateUpdate()
    {
        float lookX = Input.GetAxis("LookX");
        float lookY = Input.GetAxis("LookY");
        float moveX = Input.GetAxis("Horizontal");
        float moveY = Input.GetAxis("Vertical");

        Vector3 characterOffset = followXForm.position + new Vector3(0, distanceUp, 0);

        if (Input.GetAxis("Target") > targetingThreshold) {
            barEffect.coverage = Mathf.SmoothStep (barEffect.coverage, widescreen, targetingTime);
            camState = CamStates.Target;
        } else {
            barEffect.coverage = Mathf.SmoothStep (barEffect.coverage, 0f, targetingTime);

            // first person
            if (lookY > firstPersonThreshold && !follow.IsInLocomotion()) {
                // reset look before entering firs person mode
                xAxisRot = 0;
                lookWeight = 0;
                camState = CamStates.FirstPerson;
            }

            if ((camState == CamStates.FirstPerson && Input.GetButton("ExitFPV")) ||
                (camState == CamStates.Target && (Input.GetAxis("Target") <= targetingThreshold)))
            {
                camState = CamStates.Behind;
            }
        }

        follow.Animator.SetLookWeight(lookWeight);

        // calculate look direction based on camera state
        switch (camState) {
        case CamStates.Behind:
            // calculate direction from camera to player, kill Y, normalize
            lookDir = characterOffset - transform.position;
            lookDir.y = 0;
            lookDir.Normalize();
            break;
        case CamStates.Target:
            lookDir = followXForm.forward;
            break;
        case CamStates.FirstPerson:
            Debug.Log("fps");
            break;
        }
        targetPosition = characterOffset + followXForm.up * distanceUp - lookDir * distanceAway;
        CompensateForWalls(characterOffset, ref targetPosition);
        SmoothPosition(transform.position, targetPosition);
        transform.LookAt (characterOffset);
    }
Пример #15
0
 void ProcessLeftButton()
 {
     if(Input.GetMouseButton(0) && Service.IsMouseInsideArea()){
         pressDownTimer +=Time.deltaTime;
         Knot _knot = GetReturnedKnot(Input.mousePosition);
         if(_knot != null){
             if(camState != CamStates.pressed){
                 if(selectedKnot != _knot)
                 {
                     _knot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(true);
                     if(selectedKnot != null)
                         selectedKnot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(false);
                 }
                 selectedKnot = _knot;
                 SetInputFields();
                 if(pressDownTimer > PDTToggle && camState != CamStates.pressed){
                     camState = CamStates.drag;
                 }
             }
         }// knot != null
         else{// knot == null
             if(camState != CamStates.drag)
                 if(pressDownTimer > PDTToggle){
                     MainCamScript.CamMove();
                     camState = CamStates.pressed;
                 }
         }// knot == null
     }// mouseButtonpressedDown
     if(Input.GetMouseButtonUp(0)){
         pressDownTimer = 0;
         camState = CamStates.none;
         MainCamScript.CamStopMoving();
         pressDownTimer = 0;
     }
     if(pressDownTimer > PDTToggle && camState == CamStates.drag && Service.IsMouseInsideArea())
         MoveKnot(selectedKnot);
 }
Пример #16
0
		public void startNextTurnPlayer (Transform t)
		{
				follow = t.GetComponent<CharacterControllerLogic> ();
				followXform = t;
				//follow = GameObject.FindWithTag ("Player").GetComponent<CharacterControllerLogic> ();
				//followXform = GameObject.FindWithTag ("Player").transform;
				camState = CamStates.Behind;
				Start ();
		}
Пример #17
0
    /// <summary>
    /// Use this for initialization.
    /// </summary>
    void Start()
    {
        cameraXform = this.transform;//.parent;
        if (cameraXform == null)
        {
            Debug.LogError("Parent camera to empty GameObject.", this);
        }

        follow = GameObject.FindWithTag("Player").GetComponent<CharacterControllerLogic>();
        followXform = GameObject.FindWithTag("CameraFollowXForm").transform;
        centeredTarget = GameObject.FindWithTag("CenteredTarget").transform;
        overTheShoulderTarget = GameObject.FindWithTag("OverTheShoulderTarget").transform;

        lookDir = followXform.forward;
        curLookDir = followXform.forward;

        barEffect = GetComponent<BarsEffect>();
        if (barEffect == null)
        {
            Debug.LogError("Attach a widescreen BarsEffect script to the camera.", this);
        }

        camState = startingState;
        eyeControlState = startingEyeState;
        freeCameraViewMode = startingFreeCameraViewMode;

        if (freeCameraViewMode == FreeCameraViewModes.Centered)
        {
            //set position to centered target
            this.transform.position = centeredTarget.transform.position;
        }
        else
        {
            this.transform.position = overTheShoulderTarget.transform.position;
        }

        // Intialize values to avoid having 0s
        characterOffset = followXform.position + new Vector3(0f, distanceUp, 0f);
        distanceUpFree = distanceUp;
        distanceAwayFree = distanceAway;
        savedRigToGoal = RigToGoalDirection;

        //Eye tracking code
        fixationData = GetComponent<FixationDataComponent>();
        gazeData = GetComponent<GazePointDataComponent>();
        if (!fixationData)
        {
            fixationData = new FixationDataComponent();
        }
        if (!gazeData)
        {
            gazeData = new GazePointDataComponent();
        }
    }
Пример #18
0
		public void triggerFocusMain (CharacterControllerLogic logic, Transform t)
		{
				follow = logic;
				followXform = t;
				camState = CamStates.Behind;
				Start ();
		}
	void LateUpdate()
	{		
		viewFrustum = DebugDraw.CalculateViewFrustum(camera, ref nearClipDimensions);

		// Pull values from controller/keyboard
		float rightX = Input.GetAxis("RightStickX");
		float rightY = Input.GetAxis("RightStickY");
		float leftX = Input.GetAxis("Horizontal");
		float leftY = Input.GetAxis("Vertical");
		float mouseWheel = Input.GetAxis("Mouse ScrollWheel");
		float mouseWheelScaled = mouseWheel * mouseWheelSensitivity;
		float leftTrigger = Input.GetAxis("Target");
		bool bButtonPressed = Input.GetButton("ExitFPV");
		bool qKeyDown = Input.GetKey(KeyCode.Q);
		bool eKeyDown = Input.GetKey(KeyCode.E);
		bool lShiftKeyDown = Input.GetKey(KeyCode.LeftShift);

		// Abstraction to set right Y when using mouse
		if (mouseWheel != 0)
		{
			rightY = mouseWheelScaled;
		}
		if (qKeyDown)
		{
			rightX = 1;
		}
		if (eKeyDown)
		{
			rightX = -1;
		}
		if (lShiftKeyDown)
		{
			leftTrigger = 1;
		}
		
		characterOffset = followXform.position + (distanceUp * followXform.up);
		Vector3 lookAt = characterOffset;
		targetPosition = Vector3.zero;
		
		// Determine camera state
		// * Targeting *
		if (leftTrigger > TARGETING_THRESHOLD)
		{
			barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, widescreen, targetingTime);
			
			camState = CamStates.Target;
		}
		else
		{			
			barEffect.coverage = Mathf.SmoothStep(barEffect.coverage, 0f, targetingTime);
			
			// * First Person *
			if (rightY > firstPersonThreshold && camState != CamStates.Free && !follow.IsInLocomotion())
			{
				// Reset look before entering the first person mode
				xAxisRot = 0;
				lookWeight = 0f;
				camState = CamStates.FirstPerson;
			}

			// * Free *
			if ((rightY < freeThreshold || mouseWheel < 0f) && System.Math.Round(follow.Speed, 2) == 0)
			{
				camState = CamStates.Free;
				savedRigToGoal = Vector3.zero;
			}

			// * Behind the back *
			if ((camState == CamStates.FirstPerson && bButtonPressed) || 
				(camState == CamStates.Target && leftTrigger <= TARGETING_THRESHOLD))
			{
				camState = CamStates.Behind;	
			}
		}
		
		// Set the Look At Weight - amount to use look at IK vs using the head's animation
		follow.Animator.SetLookAtWeight(lookWeight);
		
		// Execute camera state
		switch (camState)
		{
			case CamStates.Behind:
				ResetCamera();
			
				// Only update camera look direction if moving
                if (follow.Speed > follow.LocomotionThreshold && follow.IsInLocomotion() && !follow.IsInPivot())
				{
					lookDir = Vector3.Lerp(followXform.right * (leftX < 0 ? 1f : -1f), followXform.forward * (leftY < 0 ? -1f : 1f), Mathf.Abs(Vector3.Dot(this.transform.forward, followXform.forward)));
					Debug.DrawRay(this.transform.position, lookDir, Color.white);
				
					// Calculate direction from camera to player, kill Y, and normalize to give a valid direction with unit magnitude
					curLookDir = Vector3.Normalize(characterOffset - this.transform.position);
					curLookDir.y = 0;
					Debug.DrawRay(this.transform.position, curLookDir, Color.green);
				
					// Damping makes it so we don't update targetPosition while pivoting; camera shouldn't rotate around player
					curLookDir = Vector3.SmoothDamp(curLookDir, lookDir, ref velocityLookDir, lookDirDampTime);
				}				
				
				targetPosition = characterOffset + followXform.up * distanceUp - Vector3.Normalize(curLookDir) * distanceAway;
				Debug.DrawLine(followXform.position, targetPosition, Color.magenta);
				
				break;
			case CamStates.Target:
				ResetCamera();
				lookDir = followXform.forward;
				curLookDir = followXform.forward;
				
				targetPosition = characterOffset + followXform.up * distanceUp - lookDir * distanceAway;
				
				break;
			case CamStates.FirstPerson:	
				// Looking up and down
				// Calculate the amount of rotation and apply to the firstPersonCamPos GameObject
			    xAxisRot += (leftY * 0.5f * firstPersonLookSpeed);			
    			xAxisRot = Mathf.Clamp(xAxisRot, firstPersonXAxisClamp.x, firstPersonXAxisClamp.y); 
				firstPersonCamPos.XForm.localRotation = Quaternion.Euler(xAxisRot, 0, 0);
							
				// Superimpose firstPersonCamPos GameObject's rotation on camera
				Quaternion rotationShift = Quaternion.FromToRotation(this.transform.forward, firstPersonCamPos.XForm.forward);		
				this.transform.rotation = rotationShift * this.transform.rotation;		
				
				// Move character model's head
		        follow.Animator.SetLookAtPosition(firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward);
				lookWeight = Mathf.Lerp(lookWeight, 1.0f, Time.deltaTime * firstPersonLookSpeed);
				
				
				// Looking left and right
				// Similarly to how character is rotated while in locomotion, use Quaternion * to add rotation to character
				Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, fPSRotationDegreePerSecond * (leftX < 0f ? -1f : 1f), 0f), Mathf.Abs(leftX));
				Quaternion deltaRotation = Quaternion.Euler(rotationAmount * Time.deltaTime);
	        	follow.transform.rotation = (follow.transform.rotation * deltaRotation);
				
				// Move camera to firstPersonCamPos
				targetPosition = firstPersonCamPos.XForm.position;
			
				// Smoothly transition look direction towards firstPersonCamPos when entering first person mode
				lookAt = Vector3.Lerp(targetPosition + followXform.forward, this.transform.position + this.transform.forward, camSmoothDampTime * Time.deltaTime);
				Debug.DrawRay(Vector3.zero, lookAt, Color.black);
				Debug.DrawRay(Vector3.zero, targetPosition + followXform.forward, Color.white);	
				Debug.DrawRay(Vector3.zero, firstPersonCamPos.XForm.position + firstPersonCamPos.XForm.forward, Color.cyan);
			
				// Choose lookAt target based on distance
				lookAt = (Vector3.Lerp(this.transform.position + this.transform.forward, lookAt, Vector3.Distance(this.transform.position, firstPersonCamPos.XForm.position)));
				break;
			case CamStates.Free:
				lookWeight = Mathf.Lerp(lookWeight, 0.0f, Time.deltaTime * firstPersonLookSpeed);

				Vector3 rigToGoal = characterOffset - cameraXform.position;
				rigToGoal.y = 0f;
				Debug.DrawRay(cameraXform.transform.position, rigToGoal, Color.red);
				
				// Panning in and out
				// If statement works for positive values; don't tween if stick not increasing in either direction; also don't tween if user is rotating
				// Checked against rightStickThreshold because very small values for rightY mess up the Lerp function
				if (rightY < lastStickMin && rightY < -1f * rightStickThreshold && rightY <= rightStickPrevFrame.y && Mathf.Abs(rightX) < rightStickThreshold)
				{
					// Zooming out
					distanceUpFree = Mathf.Lerp(distanceUp, distanceUp * distanceUpMultiplier, Mathf.Abs(rightY));
					distanceAwayFree = Mathf.Lerp(distanceAway, distanceAway * distanceAwayMultipler, Mathf.Abs(rightY));
					targetPosition = characterOffset + followXform.up * distanceUpFree - RigToGoalDirection * distanceAwayFree;
					lastStickMin = rightY;
                }
				else if (rightY > rightStickThreshold && rightY >= rightStickPrevFrame.y && Mathf.Abs(rightX) < rightStickThreshold)
				{
                	// Zooming in
                	// Subtract height of camera from height of player to find Y distance
					distanceUpFree = Mathf.Lerp(Mathf.Abs(transform.position.y - characterOffset.y), camMinDistFromChar.y, rightY);
					// Use magnitude function to find X distance	
					distanceAwayFree = Mathf.Lerp(rigToGoal.magnitude, camMinDistFromChar.x, rightY);		
					targetPosition = characterOffset + followXform.up * distanceUpFree - RigToGoalDirection * distanceAwayFree;		
					lastStickMin = float.PositiveInfinity;
				}				
                                
				// Store direction only if right stick inactive
				if (rightX != 0 || rightY != 0)
				{
					savedRigToGoal = RigToGoalDirection;
				}
				
			
				// Rotating around character
				cameraXform.RotateAround(characterOffset, followXform.up, freeRotationDegreePerSecond * (Mathf.Abs(rightX) > rightStickThreshold ? rightX : 0f));
								
				// Still need to track camera behind player even if they aren't using the right stick; achieve this by saving distanceAwayFree every frame
				if (targetPosition == Vector3.zero)
				{
					targetPosition = characterOffset + followXform.up * distanceUpFree - savedRigToGoal * distanceAwayFree;
				}

				break;
		}
		

		CompensateForWalls(characterOffset, ref targetPosition);		
		SmoothPosition(cameraXform.position, targetPosition);	
		transform.LookAt(lookAt);	

		// Make sure to cache the unscaled mouse wheel value if using mouse/keyboard instead of controller
		rightStickPrevFrame = new Vector2(rightX, rightY);//mouseWheel != 0 ? mouseWheelScaled : rightY);
	}
Пример #20
0
		//start to trigger this
		public void PanTo (GameObject target)
		{
				targetPos = target.transform.position;
				characterOffset = target.transform.position + Vector3.up * porportion.y;
				characterLookOffset = target.transform.position + Vector3.up * porportion.y * 0.4f;

				//groundPos + Quaternion.Euler (0, Y, 0) * Vector3.forward * 1.5f;
				//curLookDir = Vector3.Normalize (characterOffset - camera.position);
				camState = CamStates.Front;
				setTouch (false);
		}