Hi , how i can edit this code , because when i click W and Space , and when controller touches ground , Controler have move lock problem. https://pastebin.com/AiYjrrM2 Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class chodzenie : MonoBehaviour { float speed = 4f; float rotspeed = 80f; float rot = 0f; float gravity = 4f; Vector3 moveDir = Vector3.zero; public float jumpSpeed = 4f; CharacterController controller; // Use this for initialization void Start () { controller = GetComponent<CharacterController>(); } // Update is called once per frame void Update () { if (controller.isGrounded) { if (Input.GetKey(KeyCode.W)) { moveDir = new Vector3(0, 0, 1); moveDir *= speed; moveDir = transform.TransformDirection(moveDir); } if (Input.GetKeyUp(KeyCode.W)) { moveDir = new Vector3(0, 0, 0); } if (Input.GetKeyUp(KeyCode.Space)) { moveDir.y = jumpSpeed; } } rot += Input.GetAxis("Mouse X") * rotspeed * Time.deltaTime; transform.eulerAngles = new Vector3(0, rot, 0); moveDir.y -= gravity * Time.deltaTime; controller.Move(moveDir*Time.deltaTime); } }
What is a "move lock problem"? As written, nothing happens when space is pressed, only when space is released. If you released space right before you release W, then line 33 will set moveDir.y to 0 when you probably don't want the jump canceled.
When I jump or I will fall, but before I press the W key, and release W key in the air, the character will keep moving . Try jump and release W.