2D RotateAround

So I have an object that once it gets within a certain distance I want to rotate around the object in question. Well, it’s not working. It just continues to move towards.

	if(color == "yellow")
	{
		distance = Vector2.Distance(transform.position, target.transform.position);
		
		if(distance <= scaredRange)
		{
			transform.RotateAround(target.transform.position, Vector3.up, speed * Time.deltaTime);
		}
		else
		{
			transform.rigidbody2D.velocity.x = (target.transform.position.x - transform.position.x) * Time.deltaTime;
		}
	}

I’m not sure what I did wrong. The distance variable is tracking correctly. So it has to be something with my conditionals.

Only thing I can think of is that since your setting your objects velocity directly in order for it to stop moving forward you need to set it’s velocity equal to zero. Otherwise even if it’s trying to rotate around the object it’s velocity has already been hard coded to keep it moving forward.

tried adding that to it, but it says fix compiler errors and shows no errors.

Edit: Sorry, stupid mistake. Vector2 duh.

Setting the velocity to 0 prevents the RotateAround movement.