title says it all
script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerMovement : MonoBehaviour
{
Rigidbody rigi;
public float speed = 10f;
public float jumpSpeed = 10f;
public bool grounded;
void Start()
{
rigi = this.GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float X = Input.GetAxis("Horizontal");
rigi.velocity = new Vector3(X * speed, 0, 0);
if (grounded && Input.GetKeyDown(KeyCode.Space))
{
rigi.AddForce(new Vector3(0, jumpSpeed,0), ForceMode.Impulse); //this doesnt work i think
Debug.Log("jump"); //this pops up so that if statement works
}
}
public void OnCollisionEnter(Collision collision)
{
grounded = true;
}
public void OnCollisionExit(Collision collision)
{
grounded = false;
}
}
note: this script doent give any errors, it just don’t work