Center of mass not so accurate.

I’m using this to keep updating the center of mass so that when the user rotates, it will always rotate from the center of the screen.

Vector2 inversePos = cam.InverseTransformPoint(transform.position);
rigidbody2D.centerOfMass = -inversePos;

Using debug.log I can see that the center of mass is updating correctly but it seems that it’s always just slightly off center. And if it’s rotated for a long time, it will get worse.

I did notice in the console that the center of mas was being updated to one decimal point. I thought maybe for more accuracy, I would need at least a couple more.

Is there a way to increase the precision?

I don’t know whether there’s a way to increase precision, but you’re obviously getting a cumulative error because of it. You could try storing the original center of mass and always adding the calculated value to that, instead.

Are you sure that this is the best approach for keeping something rotated in the centre of screen? If you provide a quick vid or animated gif of the scenario, I might be able to suggest a cleaner approach.

t

Thanks for the reply.
I ended up putting an empty game object in the middle of the screen and used rotatearound. It works perfect for what I need.

That sounds like a solid approach, nicely done!