【问题标题】:How can I lock the player position so the player will not move but also to allow to move the player back?如何锁定播放器位置,使播放器不会移动,但也允许将播放器移回?
【发布时间】:2021-10-04 19:39:03
【问题描述】:

问题是玩家有动画师,当它空闲时播放一些动画,让玩家移动一点。

我向地形添加了 ZeroFriction 材质,但尚未更改属性中的任何内容:Dynamic Friction、Static Friction、Bounciness 均设置为 0,Friction Combine 设置为 Multiply,Bounce Combine 设置为 Average。

不确定我是否应该通过此 ZeroFriction 上的脚本更改某些内容以锁定玩家移动,或者只是禁用/启用玩家第三人称用户控件和第三人称角色上的组件。

private void Update()
    {
        if (closeCarte == false)
        {
            var heading = transform.position - player.transform.position;
            var dot = Vector3.Dot(heading, -transform.forward);

            if (dot > 1)
            {
                var lookat = player.transform.position - securityKeyPadInteractable.transform.position;
                lookat.y = 0;
                if (lookat.magnitude <= interactableItem.distance && interactableItem != null)
                {
                    if (!playAnimOnce)
                    {
                        if (ikControl.handFinishedMove == true)
                        {
                            if (securityKeyPad1 != null)
                            {
                                securityKeyPad1.SetActive(true);
                            }
                            if (virtualCam != null)
                                virtualCam.enabled = true;
                            freeLookCam2.enabled = false;
                            Cursor.visible = true;
                            camerasContorl.enabled = false;

                            // Here

                            playAnimOnce = true;
                        }
                    }
                }
                else if (playAnimOnce)
                {
                    if (securityKeyPad1 != null)
                    {
                        securityKeyPad1.SetActive(false);
                    }
                    if (virtualCam != null)
                        virtualCam.enabled = false;
                    camerasContorl.enabled = true;
                    freeLookCam2.enabled = true;
                    Cursor.visible = false;

                    if (m_hasOpened == true)
                    {
                        //anim.Play("Crate_Close");
                        //StartCoroutine(dimLights.dimLightOverTime(0, 2f));
                    }
                    playAnimOnce = false;
                    if (securityKeypadSystem != null)
                        securityKeypadSystem.ResetCode();
                }
            }
            else
            {
                securityKeyPad1.SetActive(false);
                playAnimOnce = false;
            }
        }
    }

在这一行之后:

camerasContorl.enabled = false;

我写的地方 // 这里

我想锁定(防止玩家移动),但同时也希望如果玩家按下其中一个移动键,它将释放玩家并允许再次移动。

在代码的这个地方,它显示了大的安全键盘,玩家应该输入一些代码,问题是因为玩家移动了一点,即使玩家没有按下任何移动键,他也会失去与安全键盘的联系我需要再次向前移动播放器才能再次激活安全键盘。

我想阻止玩家在地形上移动/滑动,但不想禁用移动。

玩家有这些组件:动画师,刚体(当运行游戏时,冻结旋转上的 x,y,z 被检查为真并锁定),胶囊碰撞器,第三人称用户控制和第三人称角色。

【问题讨论】:

  • 我可以添加一个取消按钮,这样它会释放玩家锁定,但我想让游戏更加流畅。在这种情况下,大多数游戏都有一个取消按钮或 X,或者如果您尝试输入 5 次代码,它将自动释放玩家。但我想让它尽可能自然,所以如果有交互“锁定”玩家在它的位置,但允许玩家远离交互对象。我认为这与生活中的情况一样,当您尝试解锁某些东西时,如果您感到疲倦或想做其他事情,则无需按下取消按钮。

标签: c# unity3d


【解决方案1】:

在动画方面,不妨看看是否启用了 Root Motion,这实际上会“移动”对象的变换。

官方参考:https://docs.unity3d.com/Manual/RootMotion.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-12
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多