Hello,
I have made a movement script for a 3lane runner type of game and I am stuck at how to make the transition between lanes slower. At the moment it is instant, it seems it is dependent by the runtime or frameupdate maybe because I am using “transform.position”. I have tried using “Time.scaletime” but it effect the speed of everything except the transition/laneSwitching. I also found this which is similar, but i did not get it working (link text).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controllers : MonoBehaviour
{
public float speed;
public int laneCount = 0;
public bool maxLaneLeft = false;
public bool maxLaneRight = false;
public Rigidbody rb;
public void Start()
{
}
public void Update()
{
rb.AddForce(new Vector3(0, 0, 1) * speed * Time.deltaTime);
Movement();
}
public void Movement()
{
if (Input.GetKeyDown(KeyCode.A) && maxLaneLeft == false)
{
transform.position += new Vector3(-5, 0, 0);
transform.eulerAngles = new Vector3(0, 0, 0);
laneCount -= 1;
}
if (laneCount == -1 && maxLaneRight == false)
{
maxLaneLeft = true;
maxLaneRight = false;
}
if (Input.GetKeyDown(KeyCode.D) && maxLaneRight == false)
{
transform.position += new Vector3(5, 0, 0);
transform.eulerAngles = new Vector3(0, 0, 0);
laneCount += 1;
}
if (laneCount == 1 && maxLaneLeft == false)
{
maxLaneLeft = false;
maxLaneRight = true;
}
if (laneCount == 0)
{
maxLaneLeft = false;
maxLaneRight = false;
}
}
}
Thanks in advance <3