Character Controller: Stop movement

Hi

I’m controlling my player with a Character Controller and Joystick (utilising the joystick script supplied by Unity).

During gameplay, if an enemy hits the player, I disable the joystick whilst the player flashes (I just turn the material on and off a few times) and the player loses a life. Joystick/control is returned to the player at the end of this.

The problem with this is that if the player is moving at the time they hit the enemy, the character keeps on moving in the direction at the time of the hit.

What I want to achieve is that as soon as the player hits the enemy they come to a standstill at that position.

For movement (in the sidescrollerscript), I’m using (in Update function):

if ( moveTouchPad.position.x > 0.7  moveTouchPad.position.x !=0){
		movement = Vector3.right * forwardSpeed * moveTouchPad.position.x;
	
	} else if (moveTouchPad.position.x < 0.7  moveTouchPad.position.x !=0) {
		movement = Vector3.right * backwardSpeed * moveTouchPad.position.x;
       }
.... etc


        movement += velocity;	
	movement += Physics.gravity;
	movement *= Time.deltaTime;

Thanks for any advice on this.

My guess is that when you disable your joystick it will keep it’s original values, in other words moveTouchPad.position.x won’t reset to 0, so the player will keep on running.
Create a boolean and set it to true when the player is hit by an enemy and update your function to something like

if ( moveTouchPad.position.x > 0.7 moveTouchPad.position.x !=0 isHit == False){

Ah, yes of course, that makes sense - didn’t even consider that (obviously). I’ll give your suggestion a shot. Thanks!