Question by 
               scoobz1234 · Jan 27, 2017 at 09:28 AM · 
                clampboundary  
              
 
              Creating Boundries on the X Axis
Creating a simple 2d game where the object (Player) follows the mouse on the x axis. my code is this:
 public int Speed = 3;
 public GameObject Player;
 void Update () {
     Vector3 screenPos = Input.mousePosition;
     Vector3 mousePos = Camera.main.ScreenToWorldPoint (screenPos);
     Vector3 PlayerPos = new Vector3 (mousePos.x, Player.transform.position.y, Player.transform.position.z);
     Player.transform.position = Vector3.Lerp (Player.transform.position, PlayerPos, Time.deltaTime * Speed);
 }
i've been trying to code in boundries to the viewport left most and right most points. either keep the mouse from leaving a windowed screen or have the object stop at the left most/ right most point until the mouse comes back into range.. any ideas?
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Space Shooter Tutorial, Player Movement and Boundaries 0 Answers
Im having trouble clamping enemies to the game area, can anyone help? 0 Answers
Clamping a Quaternion Euler 0 Answers
clamp crosshair(vector3) to player 0 Answers
periodic wall 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                