- Home /
 
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);
 }
 
               }
Answer by GEWLAR · Jan 20, 2014 at 01:55 PM
You could multiply the move factor in those lines:
 targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime);
 targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime);
 
               Add another variable to your Script
 var Speed = 2.0f;
 
               And then use it to make your camera faster:
 targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime* Speed);
 targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime * Speed);
 
              Answer by Michael Sanelli · Jan 20, 2014 at 02:57 PM
You can simply work on xSmooth and ySmooth variable
Your answer
 
             Follow this Question
Related Questions
2d camera scrolling 0 Answers
basic 2D camera setup 2 Answers
Help with conversion from javascript to c# 3 Answers
Add a polygon collider 2D using vertices of edge collider 1 Answer
How to convert a string to a type WWW 0 Answers