- Home /
Stop Character moving immediately
Hey, in my 2D game, my character slides a little bit on the x-Axis after releasing the running buttons. I want him to stop immediately on the spot when the running animation fades out and Idle comes in. How do i do this?
i tried with velocity but its read-only...
thanks a lot!
At the moment its look this way, i thought about calling a function in the first else. But i dont know what i should contain^^
function LateUpdate () { var controller : PlayerController = GetComponent(PlayerController);
//~ if (hasAnimations) { // We are not falling off the edge right now if (controller.GetHangTime() < hangTimeUntilFallingAnimation) {
// Are we moving the character?
if (controller.IsMoving() && isRunning)
{
animation.CrossFade ("run", 0.5, PlayMode.StopAll);
isLanding = false;
}
// Go back to idle when not moving
else {
if(isLanding == true && Time.time > tempTime)
{
isLanding = false;
Idle();
}
else
{
Idle();
}
}
}
}
Answer by Cameron 3 · May 11, 2011 at 05:41 PM
Even though the VARIABLES in velocity are read only, you can still assign an entire Vector3 to it, you just have to build it manually or use the zero vector. So, to stop a rigidbody in my game, what I do is:
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
This is the same as
this.rigidbody.velocity = new Vector3(0, 0, 0);
this.rigidbody.angularVelocity = new Vector3(0, 0, 0);
Answer by unity_xWZo5Ml1R-O_PQ · Jan 12, 2020 at 05:55 AM
You could try doing RigidBody.IsKinematic = true;
Your answer
Follow this Question
Related Questions
Move object forward 1 unit then stop 2 Answers
How to stop coroutines or functions 2 Answers
[illustrated!] [code!] Stop object's movement when it is close to another one 0 Answers
Stop moving box when hit other box 1 Answer
Starting a new animation, after stopping another. Without transitions. 1 Answer