【问题标题】:collision not working properly in unity when moving移动时碰撞无法正常工作
【发布时间】:2022-10-19 20:11:30
【问题描述】:

所以我有刚体,当它与另一个低速物体碰撞时,它工作得很好,但是当它高速碰撞时,它会穿过物体我一直有这个问题,我无法修复它

这是我的代码

这是我的玩家移动文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharcterController : MonoBehaviour
{
    // Start is called before the first frame update
    public Vector3 PlayerMovementVar;

    public Rigidbody Rigidbody_comp;
    // Start is called before the first frame update
    void Start()
    {
        Rigidbody_comp = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        PlayerMovement();
        
    }

    void PlayerMovement()
    {
        float horizontalAxis = Input.GetAxis("Horizontal")/30;
        float verticalAxis = Input.GetAxis("Vertical")/30;
        PlayerMovementVar = new Vector3(horizontalAxis,0f,verticalAxis);
        transform.Translate(PlayerMovementVar,Space.Self);
    }
}

【问题讨论】:

    标签: c# unity3d collision


    【解决方案1】:

    我不应该是回答这个问题的人,因为我对统一知之甚少,但我很确定这可能是因为你正在使用变换.翻译我认为它可以避免碰撞尝试使用角色控制器反而 :)

    【讨论】:

    • 那么我该怎么做呢?
    • Brackeys 有一个教程,教我关于角色控制器的知识,虽然我已经有一段时间没有这样做了,所以我只给你一个直接链接到它youtu.be/_QajrabyTJc
    【解决方案2】:

    如果你想正确使用 Unity 物理系统,你必须使用 Forces 而不是直接翻译你的游戏对象。 尝试这个:

    Rigidbody_comp.AddForce(PlayerMovementVar);
    

    代替

    transform.Translate(PlayerMovementVar,Space.Self);
    

    【讨论】:

      【解决方案3】:

      RigidBody 运动和 Transform 运动彼此不同,各自导致不同类型的运动。当用刚体移动时,为了使用它的物理能力,你应该移动它而不是通常的变换。翻译。

      Rigidbody_comp.AddForce(PlayerMovementVar);
      

      【讨论】:

        猜你喜欢
        • 2016-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-25
        相关资源
        最近更新 更多