Top.Mail.Ru
Ответы

Unity как исправить баг с прыжком?

Когда я подхожу к блоку и зажимая W + Space получается более низкий прыжок, нежели когда просто нажимаю Space

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
 using UnityEngine; 
 
public class Player : MonoBehaviour 
{ 
  [SerializeField] private float moveSpeed = 1f; 
  [SerializeField] private float jumpForce = 4.3f;  
  private Rigidbody rb; 
  private bool isGrounded; 
  private InputSystem_Actions input; 
  private Vector3 movement; 
 
  private void OnEnable() 
  { 
    input.Enable(); 
  } 
 
  private void Awake() 
  { 
    input = new InputSystem_Actions(); 
    rb = GetComponent<Rigidbody>(); 
  } 
 
  private void Update() 
  { 
    PlayerInput(); 
    if (input.Player.Jump.triggered && isGrounded)  
    { 
      Jump(); 
    } 
  } 
 
  private void FixedUpdate() 
  { 
    Move(); 
  } 
 
  private void PlayerInput() 
  { 
    Vector2 inputVector = input.Player.Move.ReadValue<Vector2>(); 
    movement = new Vector3(inputVector.x, 0, inputVector.y);  
  } 
 
  private void Move() 
  { 
    rb.MovePosition(rb.position + movement * (moveSpeed * Time.fixedDeltaTime)); 
  } 
 
  private void Jump() 
  { 
    rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);  
    isGrounded = false; 
  } 
 
  private void OnCollisionEnter(Collision other) 
  { 
    if (other.gameObject.CompareTag("Ground")) 
    { 
      isGrounded = true; 
    } 
  } 
} 
По дате
По рейтингу
Аватар пользователя
Мудрец
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
 using UnityEngine; 
 
public class Player : MonoBehaviour  
{ 
    [SerializeField] private float moveSpeed = 1f; 
    [SerializeField] private float jumpForce = 4.3f; 
 
    private Rigidbody rb; 
    private bool isGrounded; 
    private InputSystem_Actions input; 
    private Vector3 movement; 
 
    private void Awake()  
    { 
        input = new InputSystem_Actions(); 
        rb = GetComponent<Rigidbody>(); 
    } 
 
    private void OnEnable()  
    { 
        input.Enable(); 
    } 
 
    private void Update()  
    { 
        PlayerInput(); 
        if (input.Player.Jump.triggered && isGrounded) 
        { 
            Jump(); 
        } 
    } 
 
    private void FixedUpdate()  
    { 
        // Обновляем только горизонтальные компоненты скорости, оставляя вертикальную (y) без изменений. 
        Vector3 newVelocity = new Vector3(movement.x * moveSpeed, rb.velocity.y, movement.z * moveSpeed); 
        rb.velocity = newVelocity; 
    } 
 
    private void PlayerInput()  
    { 
        Vector2 inputVector = input.Player.Move.ReadValue<Vector2>(); 
        movement = new Vector3(inputVector.x, 0, inputVector.y); 
    } 
 
    private void Jump()  
    { 
        rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); 
        isGrounded = false; 
    } 
 
    private void OnCollisionEnter(Collision collision)  
    { 
        if (collision.gameObject.CompareTag("Ground")) 
        { 
            isGrounded = true; 
        } 
    } 
} 
 
Аватар пользователя
Ученик

ничего не изменилось

Аватар пользователя
Мастер

Чат гпт проси написать код

Аватар пользователя
Ученик

Все херня все по новой



Видео по теме