The Game is a Breakout Clone and I am talking about the paddle here.
I have a player that is only able to move along the x axis and is controlled by the mouse, but it’s not limited and can go through walls and also just disappear from the screen entirely if you move the mouse too much. So how do I limit the player to be only able to move between let’s say -15 and 15 on the x Axis? The Script is below, would appreciate your help.
using UnityEngine;
public class Player : MonoBehaviour
{
Rigidbody _rigidbody;
void Start()
{
_rigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
_rigidbody.MovePosition(new Vector3(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, 0, 50)).x, -17, 0));
}
}