How to use Aether Physics2D correctly?

Hey guys… don’t know whether should ask here but I give it a try How do I use the engine for a top down game? I have currently some issues but they maybe because I use it wrong. I controll my player with the arrow-keys or with wasd-keys.

I wrote some code that handle the movement like this:

``````this.body.LinearVelocity = Vector2.Zero;

var movement = Vector2.Zero;
if (inputState.IsScrollLeft())
{
movement.X = -1;
}
else if (inputState.IsScrollRight())
{
movement.X = 1;
}
if (inputState.IsScrollUp())
{
movement.Y = -1;
}
else if (inputState.IsScrollDown())
{
movement.Y = 1;
}
if (movement != Vector2.Zero)
{
movement.Normalize();

var velocity = movement * (250/100) * (float)gameTime.ElapsedGameTime.TotalSeconds;
this.body.ApplyLinearImpulse(new Vector2((int)Math.Round(velocity.X), (int)Math.Round(velocity.Y)));
}
``````

But it seams to be the wrong way, because the diagonal movement is way faster than the left,right,top or bottom.
The next thing is, how to stop the player? Each frame I manually set the LinearVelocity to zero, but that could be wrong too?

All tipps are welcome.

By calling movement.Normalize() you make movement a unit vector, it’s length is always one (1) regardless of the direction. That’s correct.
Later though, you round velocity.X and velocity.Y which snaps the vector on a 1x1 grid.

I don’t think that will cause any issue with the simulation other than it looks ‘unphysical’ for a body to stop so abruptly.
Alternately you can set dumping or apply an opposing force to stop or slow down the body.
You should avoid however setting Position/Rotation directly as this can result in unexpected behavior.

Hey, thank you for reply. I used previously that:

``````var velocity = movement * 250 * (float)gameTime.ElapsedGameTime.TotalSeconds;
this.body.Position += new Vector2((int)Math.Round(velocity.X), (int)Math.Round(velocity.Y));
``````

Now I use that:

``````var velocity = movement * (250f/100f) * (float)gameTime.ElapsedGameTime.TotalSeconds;
this.body.ApplyLinearImpulse(new Vector2((int)Math.Round(velocity.X), (int)Math.Round(velocity.Y)));
``````

And don’t have any issues. If I dont round it, I got that flickering issue again: Camera scrolling let textures flickering - #4 by EnemyArea

Why is it so diffrent? I Use (250f/100f) to get the “simulation” unit for my speed. But its much, much faster than the “normal” way. The player runs like his ass is burning