# Unity 2D - Pixel perfect movement using physics

I'm trying to make a game in the style of many NES games and I'd like object movement to do two things:

1. I want to move an exact number of pixels per update.

2. I want, for lack of a better term, absolute movement. The object should move or not move, I don't want a ramp up or down in speed.

I'm trying to do this with physics because I would like to use Unity's hitbox collision detection. Moving objects using the translation property does not allow for this, at least that is my understanding.

Any help is appreciated and if my thought process is off, I'd like any suggestions or pointers in the right direction, thanks.

Here is my move method that gets called on Update. I expect to movement to be in whole pixels, however, when I test the x and y are always fractional.

private void Move()
{
VerticalMovement = 0;
HorizontalMovement = 0;

if (Input.GetKey(KeyCode.W))
VerticalMovement = 1;

if (Input.GetKey(KeyCode.S))
VerticalMovement = -1;

if (Input.GetKey(KeyCode.A))
HorizontalMovement = -1;

if (Input.GetKey(KeyCode.D))
HorizontalMovement = 1;

this.GetComponent<Rigidbody2D>().velocity = new Vector2(HorizontalMovement * Speed, VerticalMovement * Speed);
}


If you just want to "snap" from pixel to pixel, you would probably have to set the position explicitly, like rigidbody.position = new Vector2(x, y). Manipulating the velocity will always yield fractional numbers.
Using a Rigidbody2D, you could probably use MovePosition to achieve something like this as well.
Also, you should put your code inside of FixedUpdate() for anything concerning physics interactions.