简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM