Answer the question
In order to leave comments, you need to log in
Why does sprint keep running after triggering a jump?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterControl: MonoBehaviour
{
//скорость персонажа
public float speed = 4.0f;
//скорость прыжка персонажа
public float jumpSpeed = 8.0f;
//переменная гравитации персонажа
public float gravity = 20.0f;
// переменная движения персонажа
private Vector3 moveDir = Vector3.zero;
//переменная CharacterController
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (controller.isGrounded)
{
moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDir = transform.TransformDirection(moveDir);
moveDir *= speed;
}
if(Input.GetKeyDown(KeyCode.Space)&& controller.isGrounded)
{
moveDir.y = jumpSpeed;
}
moveDir.y -= gravity * Time.deltaTime;
controller.Move(moveDir * Time.deltaTime);
//начал делать спринт и вот здесь косяк
if (Input.GetKey(KeyCode.LeftShift)&& controller.isGrounded)
{
speed = 10.0F;
}
else if (Input.GetKeyUp(KeyCode.LeftShift) && controller.isGrounded)
{
speed = 4.0F;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question