c# - 为什么我从飞机上掉下来?
问题描述
当我按 LMB 时,我从飞机上掉下来
关于问题的视频:https ://youtu.be/aLUFHlolT8E
这是针对 Unity 4.5.5 的,我有“第一人称控制器”和下面的代码
using UnityEngine;
using System.Collections;
public class run : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
public float radius;
public float force;
void Blow () {
Collider[] col = Physics.OverlapSphere (transform.position, radius);
foreach (Collider c in col) {
if (c.name != "Plane"){
c.GetComponent<Rigidbody>().AddExplosionForce (force, transform.position, radius);
}
}
}
void Update() {
CharacterController controller = GetComponent<CharacterController> ();
if (controller.isGrounded) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
if (Input.GetMouseButtonDown (0)) {
Blow ();
}
}
}
我原以为我的角色会飞到空中,但他掉了下来,当这种情况发生时,立方体动作正常
解决方案
我看过视频,首先:
1000作为爆炸力太强,基本上会导致玩家夹穿飞机然后摔倒
第二个:
手榴弹位于玩家上方,所以如果你想让他飞起来,你应该降低更多。
如果您想修复剪辑问题,请转到
编辑>项目设置>时间>固定时间步长
将 FixedTime Step 更改为较小的值,例如 0.02 但要知道这个值越小,程序运行越困难
推荐阅读
- python - 如何使用python分隔用连字符分隔的负浮点数?
- excel - 使用VBA将Excel工作表中多列中的第1行复制到多行
- java - 当我在spring jpa的nativeQuery中使用?#{#pageable}时,mysql的日志中有乱码。怎么回事?
- reactjs - 音频未在 iPhone 上播放(反应 360)
- python - 在 Pandas 中查找第一个非 NaN 值
- reactjs - 反应应用程序没有拿起 .env.development 文件?
- database - 更改列类型后如何迁移 RealmJS db?
- python-3.x - 如何获取mp3文件的持续时间
- python - 如何在 Selenium 中选择这个元素(python)
- c++ - 如何获得从负无穷到无穷的范围以在 0 到 1 的范围内表示?