- Home /
Movement Script Bug
So I edited the movement script which is represented in script reference, i tried to decrease the speed if player is not grounded so i would be able to move a little bit while i am in air(mostly jumping) but i had a very weird bug which does the vise verse. It prints not grounded to the console when i am grounded and it stops logging that when i am not grounded. If you can tell me whats is wrong i would really appreciate it :)
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump")){
moveDirection.y = jumpSpeed;
}else {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= 2.0f;
Debug.Log("Not grounded");
}
}
tried to solve from this way too but failed again:
//$$anonymous$$ovement--
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump")){
moveDirection.y = jumpSpeed;
}
if (!controller.isGrounded){
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= 2.0f;
Debug.Log("Not grounded");
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
//--$$anonymous$$ovement
http://answers.unity3d.com/questions/904538/questions-regarding-jumping.html#answer-904682
maybe this will help you, too.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Moving character along the global axis 0 Answers
destroying game object in a specific transform 2 Answers
C# move y position of object not working 2 Answers