I would like to temporarily stop the player from moving after respawning while an animation and effect plays, but I’m not sure of the method to go about doing this. Any suggestions?
well, you could disable the script controlling the movement of the player for a period of time.
All code in this reply is untested.
Pretty simple to do, Assuming you’re using JS here is how I would do it. In the movement script: make a variable to see if the player can or cant move, I’ll call this Froze:
var Froze:boolean=false;
Within the update function where you would determine the movement just make a quick if statement check before allowing the movement to work, Like so:
function Update(){
var horizontalAxis=Input.GetAxis("Horizontal");
var verticalAxis=Input.GetAxis("Vertical");
if(Froze){
horizontalAxis=0; //There really is a lot of ways to do this, But resetting the inputs to 0 is pretty much the easiest to understand without me actually knowing how your blocks of code looks.
verticalAxis=0;
}
moveDirection=Vector3(horizontalAxis,0,verticalAxis);//Assuming you're using moveDirection...
controller.Move(moveDirection*Time.deltaTime);
}
That will stop movement, if you are determining it with some sort of basic movement using the axis’s
To do this AFTER an animation you could just make froze true, wait a few seconds (length of the animation) and then set it to false as so:
function PlayingAnimationAfterSpawning(){
animation.Play("ImAliveYAYME");
Froze=true;
yield WaitForSeconds(10);//assuming it takes 10 seconds to play the animation
Froze=false;
}
That would pretty much do it.
LIKE THE GUY ABOVE SAID disabling the script would work, But I always put 10x more stuff in my movement script than basic movement… So sometimes that doesn’t work. ![]()
Thanks guys! I’m not able to disable the entire script,because there are other elements that I need, but i’ll try the method you suggested. I’m primarily working in C#, and I’ll if i can get it working.
Thanks ExDeaDguY ![]()
In all of my games I separate the input code into its own component, and just have that fire methods on my controller based on input. This way I can just disable my playerInput component to restrict the player from interacting with the character.
This is brilliant man is just what i’m looking for couple of days. You save my ass
Thanks!!
Hi all,
can any one please guide me how i can make a object move continuously upward by pressing up button just once and stop when some other key is pressed.
Something like the code in this reply ?