Question by
Droid_Void · Jul 09, 2017 at 02:27 AM ·
unity 5movement3dplatformerthird-person
Third person platformer | Player can only jump while moving. Please help.
Hello, I am creating a third person platformer and I am trying to make a custom character controller. I just fixed a large but but it has left me with another one.
I can't jump while standing still, once I move in any direction I can then jump freely like intended. I have no idea of the cause and can't find a solution anywhere, looking through my code nothing stands out as incorrect. I appreciate any help, thank you in advance. (Side note: I don't use rigidbody)
[code] public class MoveTest : MonoBehaviour {
public float walkSpeed = 10.0f;
private CharacterController controller;
private float verticalVelcoity;
private float gravity = 30.0f;
private float jumpForce = 18.0f;
// Use this for initialization
void Start ()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void FixedUpdate ()
{
//Jumping
if (controller.isGrounded)
{
verticalVelcoity = -gravity * Time.deltaTime;
if (Input.GetButton("Jump"))
{
verticalVelcoity = jumpForce;
}
}
else
{
verticalVelcoity -= gravity * Time.deltaTime;
}
//Movement
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
targetDirection = Camera.main.transform.TransformDirection(targetDirection) * walkSpeed;
targetDirection.y = 0.0f;
Vector3 moveVector = Vector3.zero;
moveVector.y = verticalVelcoity;
controller.Move(moveVector * Time.deltaTime);
controller.Move(targetDirection * Time.deltaTime);
}
} [/code]
Comment