Question by
darkdreams783 · Feb 13, 2018 at 10:28 PM ·
rigidbody2dnot workingboxcollider2drigidbody.velocity
Why won't my RigidBody 2D stop moving?,
I have made a 2D sandbox, where you can control a character. Scattered throughout the map are NPCs. I have attached Box Collider 2Ds to these NPCs, and when they are triggered, they should cause the NPC to stop moving. The problem is, they don't stop. The message displays in the console, so it does go inside the if statement. The message displays while the Player object is detected. Here is my code. NPC() is just a method that moves the NPC, but I will provide it if necessary
void StayStill()
{
Debug.Log("this is happenig right before 0,0");
RB.velocity = Vector2.zero;
Debug.Log("I Collided");
}
void OnTriggerStay2D(Collider2D P)
{
if(P.gameObject.name == "Player(Clone)")
{
StayStill();
}
else
{
NPC();
}
}
Comment