Stop Character Walking

Hi,

I use the following components,(they use rigidbody ) which are provided free from asset store, for managing a character. I need to pause my user when i press the esc button. I dont wont to pause the time.

  • ThirdPersonCharacter
  • ThirdPersonUserControl

I create a new script file for the character with the following code.

public class Pause : MonoBehaviour {
 private ThirdPersonUserControl _playerMove;

  void Start(){
     _playerMove = GetComponent<ThirdPersonUserControl>();
  }
  private void Update(){   
         _playerMove.enabled = _!playerMove.enabled;
  }
}

The problem is that when i press the escape button my character stop to get new inputs of moving, and holds the last known input.
In example, if my character is running and i press the escape button, the character continue to run and i cannot stop him until i re enable the ThirdPersonUserControl script by pressing the escape button.

What i need is, when i press the escape button to make my character in idle mode and not to move.

Thank you in advance

I’m sure there’s a good reason you toggle that script on and off every frame; though I have no idea what it might be.

oops sorry!!
now i checked it the correct code is:

public class Pause : MonoBehaviour {
private ThirdPersonUserControl _playerMove;
  void Start(){
     _playerMove = GetComponent<ThirdPersonUserControl>();
  }
   void Update(){
      if (Input.GetKeyDown(KeyCode.Escape)) {
              _playerMove.enabled = !_playerMove.enabled;
      }
  }
}

Exactly, does that work?

My last posted code works. but with the problem first post.
Thank you.

Glad you got it sorted. Keep it up! Takes time to learn all this stuff :slight_smile:

Any idea?

I’m guessing that ThirdPersonUserControl is a script that controls a Mechanim Animator… if that is the case you will also have to tell the Animator to stop.

I guess that the scripts have their own speed variables you will need to set them to zero as well. Unless it is using physics to move, then you will need to clear all the forces.

It uses rigibody to move, also the animation mechanism,
The problem is, if i disable the animator, the character freeze where bat.

I send the code

2104427–137904–ThirdPersonCharacter.cs (7.32 KB)
2104427–137905–ThirdPersonUserControl.cs (3.44 KB)

This may work.

GetComponent<ThirdPersonCharacter>().Move(Vector3.zero, false, false);

else you’ll have to get a reference to the animator and do

Animator a = GetComponent<Animator>();
a.SetFloat("Forward", 0);
a.SetFloat("Turn", 0);

thank you dterbeest,
The second solution works perfect.

do you have any idea about my second problem->Download 3d object file inside the Assets folder in run-time and load the object - Unity Engine - Unity Discussions