Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm just prototyping a simple project. I'm moving a sprite on screen using the Xbox gamepad:

public override void Update(GameTime gameTime)
        gamePad = GamePad.GetState(PlayerIndex.One);
        base.Velocity = new Vector2(vSpeed.X * gamePad.ThumbSticks.Left.X, -vSpeed.Y * gamePad.ThumbSticks.Left.Y);

    private void GetPlayerRotation()
        leftThumb = gamePad.ThumbSticks.Left;
        base.Rotation = -(float)Math.Atan2(leftThumb.Y, leftThumb.X);

This works fine to move the sprite in the correct direction (Dependent on the angle of the joystick).

However, the problem is, when I try to do a collision with a simple test object that is just a sprite, with a rectangle:

        public virtual bool Collision(Entity entity1, Entity entity2)
        if (entity1.Rectangle.Intersects(entity2.Rectangle))
            return true;
            return false;

            foreach (TestBlock block in blockList)
            if(player.Collision(player, block))
                player.vSpeed = -player.vSpeed;

Whilst this does work, and the speed is inverted, when the bool returns to false after the collision, the control scheme becomes inverted (I.e, pressing the thumbstick up moves the sprite down).

I was trying to achieve a simple bounce effect off the block.

share|improve this question
I should also add: after a second collision (Once the controls have already been inverted) the inversion is cancelled out. If it helps, i'm using a simple position += velocity in the update for movement. – Lewissss Mar 4 '13 at 13:03

Your current collision response is flawed, since you are simply inverting the variable with your speed multiplier. The way you are using that speed multiplier in your Update() method would result in your controls being reversed.

What you need to do is create a collision response based on the two objects colliding. You can try to mimic the behavior by applying an impulse on the objects in the opposite direction:

entity.Velocity *= -(player.vSpeed * impulse);

which will give you a very poor collision response. This code is just an example. You can try to refine your own response.

Another option would be to use a physics engine, which would take many things into consideration, such as the mass, velocity, direction, rotation of both entities involved in the collision to provide a more realistic collision response.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.