Как решить проблему с бесконечным полётом в Unity?
Бесконечно лечу при зажатии пробела, как решить? Нужен один прыжок..
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour
{
public float speed = 0.0f;
public float jumpSpeed = 0.0f;
public float gravity = 0.0f;
private Vector3 movedir;
private CharacterController chark = null;
private void Start()
{
chark = GetComponent<CharacterController>();
}
private void Update()
{
if (chark.isGrounded)
movedir = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")) * speed;
movedir = transform.TransformDirection(movedir);
if (Input.GetKey(KeyCode.Space))
{
movedir.y = jumpSpeed;
}
else
{
movedir.y -= gravity * Time.deltaTime;
}
chark.Move(movedir * Time.deltaTime);
}
}