I have this script that needs to make the sphere jump:
using UnityEngine;
using System.Collections;
public class MoveSphere : MonoBehaviour {
private float MovementSpeed = 2;
private bool isFalling = false;
private float JumpForce = 2;
public GameObject JumpOnOtherThenWall;
void Update()
{
float MoveHorizontal = Input.GetAxis ("Horizontal");
Vector3 Movement = new Vector2(MoveHorizontal, 0.0f);
rigidbody.AddForce(-Movement * MovementSpeed);
//Jump
if(Input.GetKeyDown (KeyCode.Space) && isFalling == false)
{
rigidbody.AddForce(Vector3.up * JumpForce * 100);
}
isFalling = true;
}
//Jump only if on the ground
void OnCollisionStay()
{
if(JumpOnOtherThenWall.name != "Wall")
{
isFalling = false;
}
}
}
The problem is that it allows the player to jump even if the player is touching the wall and not the floor, I added the if statement inside the OnCollisionStay() function in order to prevent that but now it’s not jumping at all.