简体   繁体   English

在更新循环之外的Unity3D中使用transform.Translate时,如何执行碰撞检测?

[英]When using transform.Translate in Unity3D outside of an update loop, how can I perform collision detection?

So I'm writing a small multiplayer game. 所以我正在写一个小型的多人游戏。 For this, I'm using basic cube colliders for the players. 为此,我为玩家使用了基本的立方体对撞机。 At the moment, set to isKinematic. 此刻,设置为isKinematic。

Each player is moved from the main loop, using an offset timer to account for lag/latency. 每个玩家都使用偏移计时器从主循环中移出,以解决延迟/延迟。 This works fine. 这很好。 However, with this method, collisions are a problem. 但是,使用这种方法,冲突是一个问题。 I do NOT want to use Force if I can avoid it - a previous attempt proved that to be a big issue. 如果可以避免,我不想使用“力量”-先前的尝试证明这是个大问题。 transform.Translate() works best or so it seems, but it does not account for anything hitting meshes. transform.Translate()看起来效果最好,但它并不能解决撞击网格的任何问题。 isKinematic disables OnCollisionEnter. isKinematic禁用OnCollisionEnter。 I would love to use rigidbody.velocity, but it needs to account for rotation, not four-way movement. 我想使用“ bodybody.velocity”,但它需要考虑旋转,而不是四向运动。

This is my tick code at the moment: 这是我目前的报价代码:

public void FixedStep(double T)
{
    if (Last == 0.0) Last = T;

    double Offset = System.Math.Min(T - Last, 5000);

    for (double X = 0.0; X < Offset; X++)
    {
        transform.Translate(Vector3.up * Speed * -mInput.y * Time.deltaTime);
        //mRigidBody.velocity = (Vector3.forward * Speed * mInput.y);
        transform.Rotate(Vector3.forward * TurnSpeed * mInput.x * Time.deltaTime);

    }

    Last = T;
}

I remember there used to be tutorials that combined forward movement and rotation for rigidbody.velocity, but for the life of me, I can't find them. 我记得曾经有一些教程将刚体和速度结合在一起进行向前运动和旋转,但是对于我自己的一生,我找不到它们。 Does anyone have advice on collisions with this method? 有没有人对这种方法的碰撞有何建议?

Okay, I feel stupid. 好吧,我觉得很蠢。 It's been long enough since I've done a ...somewhat conventional game that I completely forgot the proper method of using rigidbody.velocity. 自从我完成了...某种常规游戏以来,已经足够长的时间了,我完全忘记了使用刚体。速度的正确方法。

mRigidBody.velocity = transform.forward * Speed * -mInput.y; mRigidBody.velocity = transform.forward * Speed * -mInput.y;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM