Here’s the script… for some reason, it won’t let the player jump…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float moveSpeed = 5.0f;
public float jumpForce = 10.0f;
private float moveFB, moveLR;
private float verticalVelocity;
private float gravity = 12.0f;
private CharacterController player;
private bool hasJumped;
// Use this for initialization
void Start ()
{
player = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
Movement ();
if (Input.GetButtonDown ("Jump"))
{
hasJumped = true;
}
ApplyGravity();
}
void Movement()
{
//Getting inputs from WASD keys
moveFB = Input.GetAxis ("Vertical") * moveSpeed;
moveLR = Input.GetAxis ("Horizontal") * moveSpeed;
//Control the movement of the character
Vector3 movement = new Vector3(moveLR, verticalVelocity, moveFB);
//Fix the orientation of the character
movement = transform.rotation * movement;
//Moving the player
player.Move(movement * Time.deltaTime);
}
private void Jump()
{
//verticalVelocity = jumpForce;
hasJumped = true;
}
private void ApplyGravity()
{
if (player.isGrounded == true)
{
if (hasJumped == false) {
verticalVelocity = Physics.gravity.y;
}
else
{
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity = Physics.gravity.y;
hasJumped = false;
}
}
}
,Here’s the script… for some reason, it won’t jump
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float moveSpeed = 5.0f;
public float jumpForce = 10.0f;
private float moveFB, moveLR;
private float verticalVelocity;
private float gravity = 12.0f;
private CharacterController player;
private bool hasJumped;
// Use this for initialization
void Start ()
{
player = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
Movement ();
if (Input.GetButtonDown ("Jump"))
{
hasJumped = true;
}
ApplyGravity();
}
void Movement()
{
//Getting inputs from WASD keys
moveFB = Input.GetAxis ("Vertical") * moveSpeed;
moveLR = Input.GetAxis ("Horizontal") * moveSpeed;
//Control the movement of the character
Vector3 movement = new Vector3(moveLR, verticalVelocity, moveFB);
//Fix the orientation of the character
movement = transform.rotation * movement;
//Moving the player
player.Move(movement * Time.deltaTime);
}
private void Jump()
{
//verticalVelocity = jumpForce;
hasJumped = true;
}
private void ApplyGravity()
{
if (player.isGrounded == true)
{
if (hasJumped == false) {
verticalVelocity = Physics.gravity.y;
}
else
{
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity = Physics.gravity.y;
hasJumped = false;
}
}
}