Hello guys! I've got a problem. When I hold AWSD then hold spacebar, it just ends up with the character getting up a little from the ground then going back to normal, like as if nothing happened! Is there some way to fix this? Here is my script:
function OnTriggerStay ()
{
Jumped = false;
}
function FixedUpdate ()
{
//Player movement
if(Input.GetKey(KeyCode.Space) && !Jumped)
{
Jumped = true;
rigidbody.AddForce(Vector3.up * JumpHeight);
}
if(Input.GetKey(KeyCode.W))
rigidbody.velocity = transform.forward * Forward * Time.deltaTime;
if(Input.GetKey(KeyCode.S))
rigidbody.velocity = transform.forward * -MoveSpeed * Time.deltaTime;
if(Input.GetKey(KeyCode.D))
rigidbody.velocity = transform.right * MoveSpeed * Time.deltaTime;
if(Input.GetKey(KeyCode.A))
rigidbody.velocity = transform.right * -MoveSpeed * Time.deltaTime;
//Player run movement
if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
if(Input.GetKey(KeyCode.W))
rigidbody.velocity = transform.forward * ForwardRun * Time.deltaTime;
if(Input.GetKey(KeyCode.S))
rigidbody.velocity = transform.forward * -RunSpeed * Time.deltaTime;
if(Input.GetKey(KeyCode.D))
rigidbody.velocity = transform.right * RunSpeed * Time.deltaTime;
if(Input.GetKey(KeyCode.A))
rigidbody.velocity = transform.right * -RunSpeed * Time.deltaTime;
}
}
I'm guessing it's because I'm using rigidbody movement for both commands? Sorry, only started Unity about a week ago.
↧