为什么我的重力不随时间变化?

问题描述

我正在使用 unity 3d 并且我编写了一个脚本,理论上应该使我的速度在一段时间后下降,但是它保持一致的 -1。为什么我的代码没有随着时间的推移降低速度?

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


public class gravity : MonoBehavIoUr
{
    public CharacterController controller;
    public float gravityy = -10f;
    public Transform groundCheck;
    public float grounddistance = 0.4f;
    public LayerMask groundMask;
    bool isGrounded;
    UnityEngine.Vector3 veLocityy;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        veLocityy.y += gravityy * Time.deltaTime;
        controller.Move(veLocityy * Time.deltaTime);
        isGrounded = Physics.CheckSphere(groundCheck.position,grounddistance,groundMask);
        if (isGrounded && veLocityy.y < 0) ;
        {
            veLocityy.y = -1f;
        }
    }
}

解决方法

抛开我对您的代码片段的许多其他问题,isGrounded 是不是可能是真的,因此 velocityy.y 被设置为 -1f 每个更新循环?

您似乎需要使用某种调试器。

,

在这个循环中速度设置为 -1

if (isGrounded && velocityy.y < 0) ;
        {
            velocityy.y = -1f;
        }

所以你有 isGrounded

的问题