What I’m making an attempt to realize is that when a sprite strikes to a wall, it should stay on the suitable aspect of the wall, with out actions even when the hot button is supported.
Nevertheless, with the tactic that I’m utilizing (configuring the sprite within the right location after the collision), I get micro steaks after I maintain the motion key on the wall.
That is in all probability brought on by the sprite that goes again far sufficient in order that the textual content shouldn’t be thought of to be intersecting, so when the velocity is utilized, the next desk will cross, return, repeat.
How can I repair this?
(Reactive query)
public Vector2 course = Vector2.Zero;
public float velocity;
public Vector2 velocity;
public Court docket courtroom;
public bool MovePaddle(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
course = new Vector2(-1, 0);
velocity.X = course.X * velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
place.X += velocity.X;
return true;
}
if (Keyboard.GetState().IsKeyDown(Keys.Proper))
{
course = new Vector2(1, 0);
velocity.X = course.X * velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
place.X += velocity.X;
return true;
}
return false;
}
public bool CheckCollisions()
{
if (CollideBox.Intersects(courtroom.borders(1)) || CollideBox.Intersects(courtroom.borders(2)))
{
if (CollideBox.Proper >= courtroom.borders(2).Left)
{
velocity.X = -1;
this.place.X = courtroom.borders(2).Left - picture.Width;
return true;
}
else if (CollideBox.Left <= courtroom.borders(1).Proper)
{
velocity.X = 1;
this.place.X = courtroom.borders(1).Proper;
return true;
}
}
return false;
}
public override void Replace(GameTime gameTime)
{
CheckCollisions();
MovePaddle(gameTime);
base.Replace(gameTime);
}
}
Right here is an instance of the issue: