So I started a game on my own and actually it’s working pretty good, except for a little issue.
I use a sphere for my character and he have to jump. But when the sphere is on a different platform
besides the floor. The ground check is checked out contstantly.
I bet it has something to do with the script ’ cause I’m a noob at code writing.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public bool grounded = true;
public float jumpPower = 1;
public float speed;
private Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
if(!grounded && GetComponent<Rigidbody>().velocity.y == 0)
{
grounded = true;
}
if (Input.GetKey(KeyCode.Space) && grounded == true)
{
this.GetComponent<Rigidbody>().AddForce(new Vector3(0,jumpPower,0));
grounded = false;
}
rb.AddForce (movement * speed);
}
}
thanks for your help.