I’ve recently started to use MonoGame and I’m have troubles with sprites shaking
The game currently contains a few orbital bodies and a small spaceship. When the space ship is moving, the movement is smooth, but I’m trying to implement a mechanic that the ship will lock into the position of a planet.
Currently I’m just setting the position of the ship to the position of the orbital body, in this example the Earth. But when setting the position something shakes, either the planet or the ship can’t really tell which one, its minor but definitely noticeable.
For moving the planet, I get its starting angle from the position with:
angle = (float)(Math.Atan2(vec.Y, vec.X) - Math.Atan2(-1, 0));
Then I update the angle each game tick and update the position.
Vector2 newPos = new Vector2(
(float)(Math.Sin(angle) * distance),
(float)(-Math.Cos(angle) * distance));
Pos = newPos + parentBody.Pos;
angle += orbitTime * (float)gameTime.ElapsedGameTime.TotalSeconds;
if (angle > 360f) {
angle -= 360f;
}
And for the ship its just setting it’s position of the calculated position of the Earth.
The camera I use I took from this topic.
I set the spriteBatch transformMatrix to the camera’s matrix.
transformMatrix: camera.Transform
Now I don’t know where the problem of the shaking lies. Could be with the camera, the orbital position or something else.
Any help here will be amazing!
More code or the project can be included if needed!