Hi very new to C# but not new to coding well I know some basics of C++ and C-Light.
I'm trying to make an object jump, which I have succeeded but the object jumps while in the air as well, so I m using OnCollisionStay to check for collision and after only after collision is true to be able to jump again. Can anyone please help, here is the code and thanks in advance:
public class PlayerController : MonoBehaviour
{
private int isFalling = false;
public float isJumping;
void FixedUpdate ()
{
// Ball movement
float moveHorizontal = Input.GetAxis("Horizontal"); //
float moveVertical = Input.GetAxis("Vertical"); //
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); //moving the ball
rigidbody.AddForce(movement * speed * Time.deltaTime);
// Ball Jump
if (Input.GetButtonDown("Jump") && isFalling == false)
{
rigidbody.velocity = new Vector3(0, 8, 0);
}
}
// This code is supost to check if player touched the non rigid object
void OnCollisionStay(Collision colissionInfo)
{
if (collisionInfo.rigidbody)
//As you have noticed I'm stuck here
}
↧