So I am trying to make a "crossy-road " style game. But I don’t know how to handle smoothly when the player is moving to fast and trying to get out of the screen. Any idea?
This is my solution for now.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameramovement : MonoBehaviour
{
public GameObject player;
public float speednormal;
public float speedrush;
private float subs;
private void Start()
{
subs =Mathf.Abs(player.transform.position.x - transform.position.x);
}
void Update()
{
if (Mathf.Abs(player.transform.position.x - transform.position.x) < subs+4)
{
transform.position += new Vector3(speednormal, 0, 0);
}
else
{
transform.position += new Vector3(speedrush, 0, 0);
}
}
}