Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I just tried Farseer and everything is working great. My problem is, that on touch the player should get an force up. Although the touch event works well, the player did not get an force!

Here my code:

 public void Update()
    {

        if (acceleration.Y < 0)
        {
            body.Rotation += ConvertUnits.ToSimUnits(0.05f);
        }

        if (acceleration.Y > 0)
        {
            body.Rotation -= ConvertUnits.ToSimUnits(0.05f);
        }

        while (TouchPanel.IsGestureAvailable)
        {
            var gesture = TouchPanel.ReadGesture();
            if (gesture.GestureType == GestureType.Tap || gesture.GestureType == GestureType.Flick)
            {
                Debug.WriteLine("Okey");
                body.ApplyForce(new Vector2(0, -20));
            }
        }
    }


    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(playertexture, ConvertUnits.ToDisplayUnits(body.Position),null,Color.White, ConvertUnits.ToDisplayUnits(body.Rotation), new Vector2(playertexture.Width / 2, playertexture.Height / 2), 1f,SpriteEffects.None, 0f);
    }
share|improve this question
    
Does "Okey" get written? –  Benixo May 17 '12 at 16:02
    
Yes "Okey" gets written :D –  Michael May 17 '12 at 16:05
    
Force up should be (new Vector2(0, 20)? Also is that your entire update loop? I don't know Farseer but, you seem to be missing the physics update. Usually you call update on the physics engine so it can apply the forces to the bodies, detect collisions and so on. –  Byte56 May 17 '12 at 16:11
    
In by main Update loop i call: player.Update(); and the pyhsik update –  Michael May 17 '12 at 16:16
    
Thanks :D the mass was the problem :D –  Michael May 17 '12 at 16:25
show 1 more comment

1 Answer

up vote 0 down vote accepted

Is it only with the tap response that the force is not applied? If you were to just apply a force in the update loop, without conditions, would it be applied? I'm guessing not. Which could be a number of things. Ensure the player body has been added to the physics engine, and make sure the body is set to respond to forces (i.e. with some physics engines, you set the mass to 0 if you want it to be static).

share|improve this answer
add comment

Your Answer

 
discard

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.