- Home /
How to stop a moving 2D player ?
Hi, guys. I'm just wondering that is there a way to stop the moving player in C#.
Consider North,East,West & South as up, right, left & down arrow keys... Then, when we command the player to move towards North (when it is moving towards East), it is moving North-East instead of moving North...
This is my problem. So, if there exists a method to stop a moving rigidbody in c#, I can call that method before commanding the player to move towards a direction.
Answer by PommPoirAbricot · Jun 18, 2014 at 02:27 PM
you should see in rigidbody constraint
you can lock the X, y , z translation and the x, y, Z rotation
Now can you tell exactly which components are on your character ?
transform
rigibody
Scripts ?
Can you show us the script that command your character with keyboard arrows ? (copy your code, paste it on your answer and add those marks around it : < pre >< code > Your code< /code > < /pre > without blank spaces)
Actually I'm doing this for android & not for PC.I mentioned arrow keys just for understanding purpose.
The full script is a whole lot bigger. I don't want you to waste your time in roa$$anonymous$$g around it. So take a look at the important part for this query....
//This is for upward swipe..
if((currentSwipe.y > 0)&&(( currentSwipe.x > -0.5f)&&( currentSwipe.x < 0.5f)))
{
vector2 movement=new Vector2(0.0f,currentSwipe.y);
rigidbody2D.AddForce (movement * movementSpeed );
}
here currentSwipe is a vector2 which holds the difference between touchphase began & touchphase ended. And movementSpeed is just a float variable.