当我按下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 ();
}
}
}
我希望我的角色会飞到空中,但他会倒下 而且尽管发生这种情况,多维数据集仍能正常工作
答案 0 :(得分:1)
我已经观看了视频,首先:
作为爆炸力的值1000太强,基本上会导致玩家穿过飞机然后掉落
第二个:
手榴弹位于玩家上方,因此如果您希望他飞起来,您应该将其降低得更低。
如果您要解决剪辑问题,请转到
Edit> ProjectSettings> Time> FixedTimeStep
将FixedTime步骤更改为较小的值,如0.02 但是要知道,该值越小,程序运行就越困难