首页 > 解决方案 > 为什么我从飞机上掉下来?

问题描述

当我按 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 ();
    }
}
}

我原以为我的角色会飞到空中,但他掉了下来,当这种情况发生时,立方体动作正常

标签: c#unity3dunity3d-editor

解决方案


我看过视频,首先:

1000作为爆炸力太强,基本上会导致玩家夹穿飞机然后摔倒

第二个:

手榴弹位于玩家上方,所以如果你想让他飞起来,你应该降低更多。

如果您想修复剪辑问题,请转到

编辑>项目设置>时间>固定时间步长

将 FixedTime Step 更改为较小的值,例如 0.02 但要知道这个值越小,程序运行越困难


推荐阅读