如何解决为什么我的重力不随时间变化?
我正在使用 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
的问题版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。