Question by
CadenGS_ · May 18, 2017 at 10:05 PM ·
c#movementscripting beginnerjumping
I made this but why do i only jump one time
after i jump once and land i cant jump again, why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerJump : MonoBehaviour {
public bool onGround;
private Rigidbody rb;
// Use this for initialization
void Start ()
{
onGround = true;
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update ()
{
if (onGround)
{
if (Input.GetKey (KeyCode.Space))
{
rb.velocity = new Vector3 (0f, 5f, 0f);
onGround = false;
}
}
}
void onCollisionEnter (Collision other)
{
if (other.gameObject.CompareTag ("Plane"))
{
onGround = true;
}
}
}
Comment
Thank you for such an excellent script! With Yuzuke's correction, it works pretty well!
Your answer
Follow this Question
Related Questions
How do i move a cube like an actual cube?,How Can i Move a Cube? 0 Answers
How can I make my Player jump when I press a UI button? 0 Answers
Cant Jump because of my movement code. 0 Answers
character stops moving when jumping 0 Answers
Jump Using Raycast. 0 Answers