Hi,
can someone help me how to solve the problem is that the npc shakes after pushed by player?
Scenario: The NPC reaches the designated point and then turns in the designated direction to be able to perform further actions.
Unfortunately, when the player pushes the NPC, a NPC starts to shake.
Below I am attaching a video of the described problem.
Below I am attaching the code responsible for the NPC movement:
public class Npc : MonoBehaviour
{
[SerializeField] Rigidbody2D rb;
[SerializeField] float speed = 3f;
[SerializeField] Transform circle;
[SerializeField] Collider2D circleCollider;
private void FixedUpdate()
{
if ( !circleCollider.bounds.Contains(transform.position) )
{
Vector2 target = (Vector2)circle.position - rb.position;
float angle = Mathf.Atan2(target.y, target.x) * Mathf.Rad2Deg;
rb.rotation = angle;
rb.MovePosition(rb.position + target.normalized * speed * Time.deltaTime);
}
else
{
rb.rotation = 90f;
}
Debug.Log("contain: " + circleCollider.bounds.Contains(transform.position));
}
}