jobr97
jobr97

Reputation: 179

Box2d jetski on water

At the moment I am trying to code a 2d game where a jetski is riding on water. If you press on the screen the jetski should dive down and jump back up on release. How do I have to do this in Box2d? My idea was to put a rectangular body as the water and an other one as the jetski. Since I am new to box2d I don't really know how I should bring this into code. I hope one of you can help.

Upvotes: 1

Views: 126

Answers (1)

tobloef
tobloef

Reputation: 1891

Is it something like this that you want? If it, creating buoyancy, then applying a downwards force when you want the jetski to go down. The tutorial in the window, along with this page and this page, should hopefully help you get started.

Now, this might not work for you project, but the general idea is still solid. A really simple version could function like this:

  • Your characters is positioned at some pointed on the y-axis, the surface of the water.
  • When the screen is pressed, but the character downwards.
  • If the screen isn't pressed and the character is under water, move it upward.

To improve on this design you could have the character rise until it hits a point slightly above the surface, then let it fall down again, to simulate the upwards force making the character jump out of the water.

I don't know how your game is supposed to work, so you'll probably have to find your own system, but I hope some of this can be of help to you.

Upvotes: 2

Related Questions