Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

How to use Aether Physics2D correctly?

$
0
0

@EnemyArea wrote:

Hey guys... don't know whether should ask here but I give it a try :slight_smile: 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 * (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.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles