In my code my character moving left right its and the course if 3 lines but my character can move outside map i will the character can move one time left and back to middle of the map and right and back to middle. Not 2 times left because if you move 2 times left or right the character is outside map.
almost like subway surfer and othergame.
Hope you understand my bad english
My code
moveVector = Vector3.zero;
if (controller.isGrounded)
{
verticalVelocity = -0.5f;
}
else
{
// verticalVelocity -= gravity * Time.deltaTime;
}
// X - Left and Right
moveVector.x = Input.GetAxisRaw(“Horizontal”) * speed;
// Y - Up and Down
moveVector.y = verticalVelocity;
// Z - Forward and backward
moveVector.z = speed;
controller.Move (moveVector * Time.deltaTime);
}
public void SetSpeed(float modifier)
{
speed = 30.0f + modifier;
}
// it is beign called every time our capsule hits something
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.point.z > transform.position.z + controller.radius)
Death ();
}
private void Death()
{
isDead = true;
GetComponent ().OnDeath ();