Forum rules - please read before posting.

Stop player movement using scripting...

Hello! I've been working on a system of automatic doors which, when the player hits their trigger, will open automatically, and close after a time. This side of it works perfectly, but now I'm attempting to cobble up what happens when they're locked.

My thought was something along these lines:

void OnTriggerEnter(Collider col){
if (doorLocked == true) {
// Which gameobject has just collided with the trigger?
GameObject subject = col.gameObject;
Animator subAnim = subject.GetComponent<Animator> ();

subAnim.SetFloat("Speed",0.0f);

}
}

The plan here was to drop the player's "Speed" mecanim parameter to 0.0, causing the player to stop walking. This didn't work (unsurprisingly), which led to me to think that other mechanisms are driving the player character's movement beyond the simple speed value, such as where they're going, paths to get there, etc.

Is there, therefore, any means by which I can tell a character to stop moving when they hit the trigger collider? 

Comments

  • edited March 2016
    In one of those delightful examples of figuring things out for myself, I managed to get at least part of the way to sorting the matter. In order to get the player to stop, I've added the line 

    AC.KickStarter.player.EndPath ();

    The player now stops walking when they enter the trigger area.
  • EndPath() is indeed correct - though it will cause a natural slowdown in speed.  If you need an instant stop, use Halt() instead.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.