unity3d - 为什么我的重力不随时间变化?
问题描述
我正在使用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
每个更新循环吗?
似乎您需要使用某种调试器。
推荐阅读
- python - 使用关键字参数“{'pk': ''}' 的“day_new”反向。尝试了 1 种模式:['date/(?P
[0-9]+)/新/$'] - reactjs - react-bootstrap 面包屑与 react-router-dom 更改背景颜色
- reactjs - 如果windows机器上没有安装office,是否可以在react中读取xlsx?
- oracle - Oracle NUMBER 数据类型最大限制,带和不带小数点
- python - python/beautifulsoup:查找具有特定属性的上一行
- java - spring-cloud-gateway 路径路由谓词不接受“/”
- python - 在 Python 中解析逻辑 JSON 数据
- reactjs - 在 React 中使用 TypeScript 时“this.state”从何而来
- python - Discord Bot 不响应命令
- encryption - 当密钥具有特定长度(以位为单位)时,这意味着什么?