Question by
RohanGhosh · Jun 15, 2019 at 03:25 PM ·
c#movementjump
jump code character can jump twice please any one fix this
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why doesn't the collider work? 1 Answer
C# Code won't ket me jump 0 Answers
Player not moving or sprinting while jumping 0 Answers
Jump Using Raycast. 0 Answers
how do I make my character jump while running without losing all your speed 1 Answer