0
\$\begingroup\$

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);
    }
\$\endgroup\$
4
  • \$\begingroup\$ Does "Okey" get written? \$\endgroup\$
    – Benixo
    May 17, 2012 at 16:02
  • \$\begingroup\$ Yes "Okey" gets written :D \$\endgroup\$
    – Michael
    May 17, 2012 at 16:05
  • \$\begingroup\$ 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. \$\endgroup\$
    – House
    May 17, 2012 at 16:11
  • \$\begingroup\$ In by main Update loop i call: player.Update(); and the pyhsik update \$\endgroup\$
    – Michael
    May 17, 2012 at 16:16

1 Answer 1

0
\$\begingroup\$

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).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .