- Home /
 
clamping the x and z axis but not the y axis?
So the title says it all. i need help with only clamping the x and z axis for my movment but not the y axis. i'm very new to coding so i just could'nt figure it out, sorry i couldn't get some things inte the box, this is my first post. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class move : MonoBehaviour { Rigidbody rb; public float maxspeed = 10; public float distoground = 1; public bool noinputs public bool IsGrounded;
// Start is called before the first frame update void Start() { rb = GetComponent(); }
 // Update is called once per frame
 void Update()
 {
     if(IsGrounded == true)
     {
          rb.isKinematic = false;
     }
     if(Input.GetKey(KeyCode.W))
     {
         rb.AddForce(new Vector3(0, 0, 5f));
     }
     if(Input.GetKey(KeyCode.S))
     {
         rb.AddForce(new Vector3(0, 0, -5f));
     }
     if(Input.GetKey(KeyCode.A))
     {
         rb.AddForce(new Vector3(-5f, 0, 0));
     }
     if(Input.GetKey(KeyCode.D))
     {
         rb.AddForce(new Vector3(5f, 0, 0));
     }
     if(Input.GetKeyDown(KeyCode.Space) && IsGrounded == true)
     {
         rb.AddForce(new Vector3(0, 300f, 0));
     }
     if(Input.anyKey)
     {
         noinputs = false;
     }
     else
     {
         noinputs = true;
     }
     if((IsGrounded == true) && (noinputs == true))
     {
         rb.isKinematic = true;
     }
     else
     {
         rb.isKinematic = false;
     }
     
 }
 void FixedUpdate()
  {
     GroundCheck();   
  }
  void GroundCheck()
 {
     if (Physics.Raycast(transform.position, Vector3.down, distoground + 0.1f))
     {
         IsGrounded = true;
     }
     else
     {
         IsGrounded = false;
     }
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
Working out Difference in Rotation 2 Answers
Modify distance with var? 1 Answer
Counter issues, hitting -1? 1 Answer
Raycast - Clamp Math Issue 0 Answers
How to Clamp X-axis Movement only? 1 Answer