Quantcast
Viewing latest article 24
Browse Latest Browse All 92

Camera speed

here is the cs file. how to make it follow player faster? and can you convert it to java file? using UnityEngine; using System.Collections; public class CameraFollow : MonoBehaviour { public float xMargin = 1f; public float yMargin = 1f; public float xSmooth = 1f; public float ySmooth = 1f; public Vector2 maxXAndY; public Vector2 minXAndY; private Transform player; void Awake () { player = GameObject.FindGameObjectWithTag("Player").transform; } bool CheckXMargin() { return Mathf.Abs(transform.position.x - player.position.x) > xMargin; } bool CheckYMargin() { return Mathf.Abs(transform.position.y - player.position.y) > yMargin; } void FixedUpdate () { TrackPlayer(); } void TrackPlayer () { float targetX = transform.position.x; float targetY = transform.position.y; if(CheckXMargin()) targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime); if(CheckYMargin()) targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime); targetX = Mathf.Clamp(targetX, minXAndY.x, maxXAndY.x); targetY = Mathf.Clamp(targetY, minXAndY.y, maxXAndY.y); transform.position = new Vector3(targetX, targetY, transform.position.z); } }

Viewing latest article 24
Browse Latest Browse All 92

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>