Enemy Ahead!


Just wanted to share the current status of the ship simulator I am trying to create:


Buoyancy still not perfect yet, but I am getting closer. It is just a matter of fiddling around with the settings. Same goes for the waves: I am trying to generate waves based on an integer defining the sea state (from 0 -> no wind to 8 -> storm). Problem is there are many parameters to be set for each state to get nice waves.

Ship is able to move forward and backwards and also steering is implemented. Accellerations are way to high, but that will be fine-tuned soon. Also the ship will hang over in the turns and I have to implement steering functionality when the propellor is not generating trust (so steering based on ships speed).

There is currently one gun on the model which is able to track a selected target and fire a shell on it. Math is not optimized yet, so the shell will most likely miss :). Also, there is no collision detection yet.

I had the model textured, buit somehow this got messed up after I started to import the model directly from Blender, so that I still have to check and fix.

Well, can't say it enough: jMonkeyEngine is a great utility which can be a lot of fun for a 'happy-hobby-programmer' like me. Giving me a lot of headaches as well, but that can be blamed entirely on my lack of programming knowledge :).

So, I would like to end with a big THANK YOU to all the developers working on jMonkeyEngine, because they give me a perfect tool to hobby around! Who knows where this game (I think I will call it 'Enemy Ahead' for now) will end.

Click on the embed youtube… button and paste the youtube link.


Edited your post (and memonick’s) to fix the YouTube link. All you need is an ordinary, clean YouTube link which you had, except you had somehow gotten two identical links lined up with one another without any space in between which made it unreadable.

This looks really cool! Buoyancy is something we’d be interested in for the core of the water system eventually. Any insight you can share as you delve into the topic could come in handy for other developers.

that look really awesome, great stuff

Okay, got the link working! Is it possible Internet Explorer 9 is messing up? Because i just added the link again on FireFox and now it works.

@erlend_sh: I can share the code I currently use for the buoancy, although I have to say it is very limited and pragmatic, but it seems to start to work. Basically, I just check 6 points on the ships hull for being below or above the water surface. When above, a downward force (sort of simulating gravity) is applied on that specific location, when below the surface, an upward force is applied. i tried to have it work with gravity set to (0, -9.81, 0) but this gives very messy results, so I have set the gravity back to 0 and apply my own gravity force on the ship (this also because it seems to be impossible to set an upward force on an object which will compensate for the gravity (to be specific: I have not managed (yet) to make an object hover purely by applying forces). In the real world, one would say: “gravity is 9.81, so applying an upward force of 9.81*mass will make the object hover”. On the computer, this is not true (and with my lack of knowledge of programming, I am not able to explain this).

I will test some more and try to optimize (and standardize) the forces and locations to make a more realistic and easier to use simulation of the buoyancy. At this moment, i just add control points in my Ship-class manually and by trial and error I try to find good parameters which will make it LOOK good. I want to have a method which just analyses the ships hull and defines where to put the control points by itself.

Even better would be to have something which determines the volume below the surface and applies a force based on that.

Actually in the real world an upwards force of 9.81 will cause something to spin around and crash.

There is a lot of stabilisation and compensation needed to stop things like gravity and atmospheric fluctuations, not to mention weight movements on board the hoverer, destabilizing things.

True, but one would expect in jBullet that applying an upward force of gravity*mass would keep the object hovering, not pushing it to the sky. The object keeps straight (no spinning) but goes up in the air fast.

I will try to make a small test case outside the game, to make sure there are no other things having impact on the forces. See whether the object will hover or not. Just an object, gravity and a counterforce. See where that leads to.

Maybe you didn’t include tpf in your force or something?

Hmmm… I thought this wasn’t necessary when an PhysicsTickListener was implemented and all the forces are applied in the prePhysicsTick()?

Looks like I need to study some more…

“gravity is 9.81, so applying an upward force of 9.81*mass will make the object hover”

Fnet = ma right? That means total force... For an object to hover the Fnet must be 0 therefore net acceleration must be 0 (because you can't have 0 mass - for non static atleast) . What you're doing is constantly pushing your object up (force of 9.81*mass).
I'm not sure how you're going to get it to hover because I'm busy planning an rts, and it doesn't need this kind of physics so I havn't checked it up.

But on topic fantastic looking game!

Not entirely correct.

F [N]= ma [kg] [m/s^2] ← true

But gravity ‘g’ is just an acceleration. The gravity FORCE on an object equals mass
g. So, setting the gravity (g) to 9.81 [m/s^2] means that an object with a mass of, say, 10 kg, will ‘feel’ a constant down force of 10*g = 98.1 [N].

So, to make it hover, it should be enough to apply a counter force of 98.1 [N] upwards.

Yeah lol I realised that after I posted, i’m not sure how gravity works on jmonkey so I can’t really help…

Have you tried applying an upwards force of 9.81?(and not 9.81*mass)

For it to hover I think it needs 0 vertical speed also.

@husky said:
Hmmm... I thought this wasn't necessary when an PhysicsTickListener was implemented and all the forces are applied in the prePhysicsTick()?

Looks like I need to study some more...

Well I've not used the physics stuff much myself so don't read too much into things. I was just trying to think of a reason it might not be working and not allowing for tpf would explain his symptoms.

Sweet. the water is well imported and the ship-behaviour looks really nice.

I would be definitely interested in sharing (there are some sail ships that could be profit from this idea).

1 Like


Congrats man! Keep up with the good work, the ship’s movement looks real, not synched with the wave, but that’s just an issue of this moment!

Small update on the game:

Naval Combat Simulator project in jMonkeyEngine. Current status:

  1. Sea state can be changed
  2. Multiple camera views
  3. Ships reacting to waves by jusing jBullet
  4. Rough targeting system implemented
  5. Explosions implemented
  6. Player ship controls: Engine, Rudder, Targeting


nice work,

it’s only my opinion, but i think that waves are too big(or ships too small).

Yea, considering the ships look to be a larger ships from the size of the cannons, I would assume the waves are some 15 meters high.

This is surely possible in real life, but then they would be further apart, and also you might want to reduce the horizontal noise (noise along one wave).

Really nice water, keep sending news!

Do you have homepage for the project?