- Home /
 
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               Batclone204 · Mar 03, 2021 at 10:39 PM · 
                movementmovement scriptcharacter movement  
              
 
              How do I make a 3d character only walk backwards?
All in the title really, how would I make a character in 3d that can only walk backwards? I can make it move forward and back but I need to just walk back. Here's my code:
public class PlayerMove : MonoBehaviour { public Rigidbody rb; public Transform _camera;
 public float moveSpeed = 6f;
 public LayerMask Ground;
 void Start()
 {
     
 }
 void Update()
 {
   
     //facing direction
     Debug.DrawLine(_camera.position, transform.forward * 2.5f);
     //moving
     // float x = Input.GetAxisRaw("Horizontal") * moveSpeed;
     float y = Input.GetAxisRaw("Vertical") * moveSpeed;
     //setting movement
     
     Vector3 move = transform.forward * y; // transform.right * x + .....
     
     rb.velocity = new Vector3(move.x, rb.velocity.y,move.z);
 }
 
               }
e
               Comment
              
 
               
              Answer by $$anonymous$$ · Mar 04, 2021 at 01:04 AM
Try Clamping y between 0 and -1.
It might work.
If you dont know how to clamp here check this link out : Mathf.Clamp
Your answer