using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
// Floats and variables
[SerializeField]
private float speed = 5f;
private float xMov;
private float zMov;
public Vector3 Jump;
[SerializeField]
public float JumpForce = 2f;
public bool isGrounded;
Rigidbody rb;
// Start is called atr the start of the game
void Start()
{
rb = GetComponent<Rigidbody>();
Jump = new Vector3(0f, 2f, 0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
// Update is called once per frame
void Update()
{
//Movement
xMov = Input.GetAxis("Horizontal");
zMov = Input.GetAxis("Vertical");
Vector3 movementValue = new Vector3(xMov, 0.0f, zMov);
transform.position += (movementValue * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
isGrounded = false;
rb.AddForce(Jump * JumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
