Answer the question
In order to leave comments, you need to log in
How to prevent the character from moving outside the camera?
using UnityEngine;
public class PlayerControll : MonoBehaviour
{
public float horizontalSpeed;
public float speedX;
public void MoveLeft()
{
speedX = -horizontalSpeed;
}
public void MoveRight()
{
speedX = horizontalSpeed;
}
public void MoveStop()
{
speedX = 0;
}
void FixedUpdate()
{
transform.Translate(speedX, 0, 0);
}
}
Answer the question
In order to leave comments, you need to log in
If he touches one of the barriers with the borders (extreme points), forbid him to move. Every time a player moves to the right or left, check if he has gone out of bounds, if he starts to go out, then prohibit movement in that direction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question