0

I'm developing a platformer game with C# XNA and Farseer where the player should be able to swap gravity and run on the roof. Other objects affected by gravity will be there as well.

Is there any way I can control the gravity individually for each objects? i.e letting the player to have negative gravity and some boxes have normal gravity.

Thanks

Jitender Dev
  • 6,907
  • 2
  • 24
  • 35
Oskar Eriksson
  • 845
  • 1
  • 9
  • 28
  • Have you considered turning gravity off and applying forces to each object? – craftworkgames Oct 04 '13 at 11:49
  • Well yes I have. But i was hoping for a more simple solution. I have thought of having the gravity on but only letting it affect the player, and then ignore gravity on all other objects. I guess this would make it possible to simulate up AND down gravity on objects, but with some more work. – Oskar Eriksson Oct 04 '13 at 15:13

1 Answers1

2

I can't believe no one answered this for you yet. But if you do the following:

Body.GravityScale = -1.0f;

You simply give the body of the player a negative gravity by multiplying it with a scale of -1.0f. If your player consists out of multiple bodies like mine, you change all of their gravity scales to -1.0f. Learned something new myself, haha.

Hope this helps and I wasn't too late.

Blackunknown
  • 195
  • 4
  • 15
  • 1
    Thanks, that solved everything! I couldn't find it myself since apparently this functionality only exists in Farseer 3.5 and I had 3.3. – Oskar Eriksson Nov 04 '13 at 12:18