- Home /
cube jump - script not working and with no errors
hello I’m making an endless runner kinda thing there’s the problem: the cube jumps just one time and then it doesn't jump at all when it fall in the next tile / ground Any help ??
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 15.0F;
private Rigidbody rb;
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
//Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.forward * (speed) * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
Answer by matthrewp · Jul 30, 2016 at 03:08 PM
Your not setting IsGrounded to true when you land. You could do this with this code:
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "insert platform object name here")
{
isGrounded = true
}
}
Hope this helps!
I did as you said and I did a different one as well to test it still jumps in the first time and then nothing, the ground be true just in the first time and then turns false for ever :(
void onCollisionEnter(Collision other) { if(other.gameObject.CompareTag("Ground")) { isGround = true; } }
If this is copied from your code, your isGrounded is accidentally isGround. Otherwise, I don't know what's wrong.
Your answer
Follow this Question
Related Questions
Why is my raycast projecting from the middle instead of the bottom? 0 Answers
Why is my 2d jumping script weird? 1 Answer
Unity autojump script glitch 1 Answer
Character Getting Stick on Walls, Jumping Prob in Unity 0 Answers
Help with jump cooldown 2 Answers