0
votes

The problem is that the player have animator and when idle it's playing some animation that make the player moving a bit.

I added to the terrain a ZeroFriction material but didn't change anything yet in the properties : Dynamic Friction , Static Friction , Bounciness are all set to 0 and Friction Combine is set to Multiply and Bounce Combine to Average.

Not sure if I should change something by script on this ZeroFriction to lock the player from moving or just to disable/enable the components on the player Third Person User Control and Third Person Character.

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;
            }
        }
    }

At this point after this line :

camerasContorl.enabled = false;

Where I wrote // Here

I want to lock(prevent from the player to move) but also to make that if the player is pressing one of the movement keys it will release the player and will allow to move again.

At this place in the code it's showing big security keypad and the player should type some code the problem is that because the player is moving a bit even if the player is not pressing any movement keys he lose the touch with the security keypad and I need to move the player forward again to activate the security keypad again.

I want to prevent from the player to move/slide on the terrain but not to disable the movements.

The player have this components : Animator , Rigidbody(when running the game x,y,z on the freeze rotation is checked true and locked) , Capsule Collider , Third Person User Control and Third Person Character.