Проблема с прыжком персонажа

как бы я не пытался сделать прыжок персонаж ни в какую не хочет прыгать в право в лево двигается а прыгать никак. если что в input mannager на jump стоит прыжок я проверял

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour

{
public float speed = 10f;
public CharacterController controller;
public Transform groundcheck;
public float gravity;
public LayerMask groundMask;
Vector3 velocity;
public bool isgrounded;
public float groundDistance = 0.4f;
public float jumpHeight = 3f;

void Update()
{
    isgrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
    if (isgrounded && velocity.y < 0)
    {
        velocity.y = -2f;
    }

    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");
   
    Vector3 move = transform.right * x + transform.forward * z;
    controller.Move(move * speed * Time.deltaTime);

    velocity.y = gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);

    if (Input.GetButtonDown("Jump") && isgrounded)
    {
        velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
    }

}
}

введите сюда описание изображения


Ответы (1 шт):

Автор решения: endless light year

Ваш персонаж не считается находящимся на земле, что препятствует возможности выполнения прыжка. Это происходит из-за того, что метод isground не активирован. Для того чтобы персонаж считался на земле, необходимо добавить компонент

Rigidbody2D

и коллайдер. Кроме того, на земле также должен присутствовать коллайдер.

→ Ссылка