Please understand that this is a work in progress and is updated as my time allows. I made this for fun. It is released as open-source for those that wish to develop a car game and would like to see some kind of demonstration of how to go about developing a car in jMonkeyEngine. Contributions are welcome!
An advanced implementation of vehicles for jMonkeyEngine.
This is a work in progress of creating individual parts for a vehicle. Currently implemented (but may not be fully implemented) are:
Engine
Brakes
Automatic GearBox
Wheel
Tyres
Suspension
Speedometer
Tachometer (rev counter)
Skid marks
Tyre Smoke
Engine Audio
Vehicle Editor
There are 5 cars to play with.
Controls:
WASD : forward, left, brake, right
Y : Start Vehicle
R : Reset Vehicle
H : Horn
E : Reverse
F5 : Change View (use numpad in 3rd person mode to change view angle) .
ESC : Exit Game
Pacejka Data
The tyres use the pacejka formula. Currently only latitudinal forces are applied, but longitudinal code is there. There are probably a few more things I canāt remember.
The project also contains a Pacejka Viewer/Editor so you can create tyre models yourself. This is particularly handy if you want more of an arcade or simulation feel.
It can be a simulation if you want to spend endless months perfecting every single number. You could probably get somewhere near without a great deal of messing around. Personally Iām just having fun.
Wow! This is now starting to even look beautiful Iād suggest adding shadows if you want to go for that realistic look, since thatās all that is really missing for it
I have some questions. Feel free to redirect me to the code or documentation. Iām partly asking them in case there are easy answers or it leads to further discussionā¦ but mostly just so I donāt forget to look up the answers myself if I have to.
I assume that you are not using bulletās vehicle control and this is custom.
Do you know if it works with jbullet or only native bullet? (I had problems with jbullet in my world with the car not moving at allā¦ even though jbullet works fine in the TestFancyCar.) Edit: the reason I ask is because I would really prefer to use jbullet for āreasonsā.
What is the licensing on these with respect to commercial use?
I take this to mean that acceleration and braking does not factor into grip? But the code is thereā¦ If it works that would be good as I think itās pretty important with respect to braking/acceleration on turns, front wheel vs rear wheel, etcā¦
Random comments after watching the video in the first postā¦ so excuse me if these are fixed in later versions. (I will look deeper into all of this hopefully later tonight.)
I agree with grizeldi regarding shadows. Adding the directional light shadow renderer and setting the cast/receive would really make this pop. In my own prototype, it was crucial for knowing when the car is/isnāt on the ground. Yours look like they are floating until they leave the cool tire tracks.
Also, you might consider altering your grid texture to have more variation between the levels of grid lines. Like, really dark on the LARGE grid and a medium level and the smallest being almost invisible. The only reason I saw this is because in the video it just ends up strobing and itās hard to tell if the car is moving forwards or backwards at some points.
I had this same issue with my bullet character demo. Jaime looked like he was running around backwards until I increased the grid size.
But these are really minor nits on the demo. The tech itself looks super cool.
It uses the Bullet PhysicsVehicle. Its extends its functionailty. For example the PhysicsVehicle provides an accelerate function and I pass it through a graph to determine how much power it delivers at x revs. Thatās pretty much how each āextensionā of the PhysicsVehicle works.
It works with native bullet, jbullet and the minie library by @sgold .
I got them from sketchfab. If you find a vehicle you like in particular with a license that fits what you want I donāt mind adding it for you.
In order to use both lat and long forces the developer also has to include a āfriction circleā - which I did begin to implement, but kind of ran out ot time and entheusiasm, and must admit I did struggle a little trying to provide the feedback the formulas require.
It takes a lot of tweaking. I could spend more time on getting them working. I guess the more interest the library has - the more interest Iāll have in continuing its development.
To actually add a car to a game, you just need to add the CarSelectorState to the stateManager (or just look at the setVehicle method in that class):
stateManager.attach(new VehicleSelectorState(scene, physicsSpace));
// ...
Car tourer = new GrandTourer(app);
getState(VehicleSelectorState).setVehicle(tourer);
tourer.getVehicleControl().setPhysicsLocation(new Vector3f(x, y, z));
Note that the scene you pass is the one the car will be added to, and usually has a lightprobe affecting it. I create my scenes with my intelliJ plugin and generate/save a lightprobe in the scene - which is faster than generating one at runtime - so itās not necesarrily always ārootNodeā that you pass as the scene.
Iāve added the shadows and SSAO. Took me a short while to realise the skybox was stopping the shadows working. Had to set it to shadow-mode off.
Fixed the 3rd person camera. Just use the mouse to drag rotate.
Tweaked the Nismo car. The wheels are positioned better and the suspension is more in-key with how itās supposed to work.
Did a bunch of bug fixes, mainly related to debug data not working when you changed car.
Iāll push a new release in a few days when Iāve tweaked the tourer and added another vehicle. Iām most likely going to replace all the simple models with professional ones, and maybe more variety (bus, monster truck, etc).
Iāve begun to implement longitudinal forces. You will notice now that if you accelerate through a corner you are more likely to skid if you are at high speed and/or rear-wheel. I still need to include braking in these factors, but you can powerslide and recover and not accelerate around corners to avoid sliding, so itās definitely on its way.
Iāve added the ability to specify wheel models, so each car can use any wheel - they are not model-specific anymore. This basically means that you can swap/upgrade wheels on the fly.
I changed the grid texture to a marble tile instead. The grid was hurting my eyes after a while.
The skid marks now have an alpha value, so light skids make light marks and heavy skids make darker marks. Notice now how they āfade offā instead of abruptly starting and stopping. Pretty cool.
Thanks, man. Thereās still a lot to do but itās definitely fun. The vehicles wheelspin but the gearbox changes when it redlines, so they change instantly. I think it will feel a lot nicer when I fix that so it changes at the right speed and you can tell itās wheelspinning. Damage would be cool. I guess it never ends
From what I could tell on discord, Riccardo was questioning the hosting costs with Jayfella again. From reading other forum threads it looks like Jayfella has been looking to exit the community because of the lack of growth in jME and that whole discussion prompted him to throw up his hands and he transferred all the server admin stuff over to Riccardo and dropped all his repos from github. He removed all his repos last time this happened so Iām not sure if you should expect them back.
Iām disappointed about the SDK he was working on. I had my particle system running inside of it and was just working on the curve editor. The existing SDK has been a pain to try to create a plugin for so I was hoping for something easier.