My Perfect Climbing Cam Solution

I wanted my cam shows above or below while I’m going upwards or downwards on ladder. So I wrote a simple script which place a game object on the way player goes and focused my climbing cam to that object.
This object parented by player and there is no linear extrapolation (lerp). Lerp thing is handled by cinemachine in visual so it’s easier to achieve good results with less coding.
All the thing you have to do is create a child game object to player and attach this script. In unity editor do not forget to show player to this gameobject in inspector. Here is code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

public class Player_HeadOn : MonoBehaviour {
	public Transform player;
	Vector2 Player_Head_Vector;
	float verticalNew;
	float horizontalNew;
	[SerializeField] [Range(1f,6f)] float commonOffsetAsMultiplier;
	void Update () 
	{
		if(CrossPlatformInputManager.GetAxisRaw("Vertical")!=0)
		{
			verticalNew =  CrossPlatformInputManager.GetAxisRaw("Vertical")*commonOffsetAsMultiplier + player.transform.position.y;
		}
		if(CrossPlatformInputManager.GetAxis("Vertical")==0)
		{
			verticalNew = player.transform.position.y;
		}
		if(CrossPlatformInputManager.GetAxisRaw("Horizontal")!=0)
		{
			horizontalNew = CrossPlatformInputManager.GetAxisRaw("Horizontal")*commonOffsetAsMultiplier + player.transform.position.x;
		}
		if(CrossPlatformInputManager.GetAxis("Horizontal")==0)
		{
			horizontalNew = player.transform.position.x;
		}
	}

	void FixedUpdate()
	{
		this.transform.position = new Vector2(horizontalNew, verticalNew);
	}
	void OnDrawGizmos()
	{
		Gizmos.color = Color.white;
		Gizmos.DrawWireSphere(transform.position, 2f);
	}
}

Privacy & Terms