I don’t know why… what’s wrong with the script, before I click start it is touching the floor but when I hit play a gap occurs
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveVector;
private float speed = 7.0f;
private float verticalVelocity = 0.0f;
private float gravity = 12.0f;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
transform.Rotate(6, 0, 0);
moveVector = Vector3.zero;
if (controller.isGrounded)
{
verticalVelocity = -0.5f;
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
// X - Left and Right
moveVector.x = Input.GetAxisRaw("Horizontal") * speed;
// Y - Up and Down
moveVector.y = verticalVelocity;
// Z - Forward and Backward
moveVector.z = speed;
controller.Move(moveVector * Time.deltaTime);
}
I’ve tried to change verticalVelocity from -0.5f to 0.5f and 0.0f and 100.0f whatever, it still doesn’t touch the ground after I hit play.
Any help please? thanks,respectfully!