I can’t jump after jumping once, here is my code, please help:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour
{
public Rigidbody rb;
public bool IsGrounded = true;
public float groundDist;
public bool Israycastgrounded = true;
public bool Isdoubleraycastgrounded = true;
public bool Istripleraycastgrounded = true;
public Vector3 raycastoffset = new Vector3(0, 0, 0.5f);
// Start is called before the first frame update
void Start()
{
groundDist = GetComponent<Collider>().bounds.extents.y;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded && Israycastgrounded && Isdoubleraycastgrounded && Istripleraycastgrounded) {
GetComponent<Rigidbody>().AddForce(transform.up * 7, ForceMode.Impulse);
IsGrounded = false;
Israycastgrounded = false;
Isdoubleraycastgrounded = false;
Istripleraycastgrounded = false;
}
if (!Physics.Raycast(transform.position, -Vector3.up, groundDist + 5)) {
Israycastgrounded = false;
print("no");
}
else {
Israycastgrounded = true;
print("yes");
}
if (!Physics.Raycast(transform.position - raycastoffset, -Vector3.up, groundDist + 5)) {
Isdoubleraycastgrounded = false;
print("no1");
}
else {
Isdoubleraycastgrounded = true;
print("yes1");
}
if (!Physics.Raycast(transform.position + raycastoffset, -Vector3.up, groundDist + 5))
{
Istripleraycastgrounded = false;
print("no2");
}
else
{
Istripleraycastgrounded = true;
print("yes2");
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.name == "Ground" || collision.gameObject.name == "Platform") {
IsGrounded = true;
}
}
} }
,Whenever I jump it stops letting me jump, please help.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour
{
public Rigidbody rb;
public bool IsGrounded = true;
public float groundDist;
public bool Israycastgrounded = true;
public bool Isdoubleraycastgrounded = true;
public bool Istripleraycastgrounded = true;
public Vector3 raycastoffset = new Vector3(0, 0, 0.5f);
// Start is called before the first frame update
void Start()
{
groundDist = GetComponent<Collider>().bounds.extents.y;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded && Israycastgrounded && Isdoubleraycastgrounded && Istripleraycastgrounded) {
GetComponent<Rigidbody>().AddForce(transform.up * 7, ForceMode.Impulse);
IsGrounded = false;
Israycastgrounded = false;
Isdoubleraycastgrounded = false;
Istripleraycastgrounded = false;
}
if (!Physics.Raycast(transform.position, -Vector3.up, groundDist + 5)) {
Israycastgrounded = false;
print("no");
}
else {
Israycastgrounded = true;
print("yes");
}
if (!Physics.Raycast(transform.position - raycastoffset, -Vector3.up, groundDist + 5)) {
Isdoubleraycastgrounded = false;
print("no1");
}
else {
Isdoubleraycastgrounded = true;
print("yes1");
}
if (!Physics.Raycast(transform.position + raycastoffset, -Vector3.up, groundDist + 5))
{
Istripleraycastgrounded = false;
print("no2");
}
else
{
Istripleraycastgrounded = true;
print("yes2");
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.name == "Ground" || collision.gameObject.name == "Platform") {
IsGrounded = true;
}
}
} }