[SOLVED] How to add collision detection to barrier

So I’m working on a car racing game that I eventually plan to publish on steam.
One of the tracks is a “flooded city” map, and it has walls to prevent the driver from falling into the water. My question is how would I add collision detection to the walls to prevent the car from passing through it?
Here is my code for one of the barriers, I’m wondering what I would need to add, the wiki isn’t really clear on how to do this

Spatial f2 = assetManager.loadModel("Models/fenceStraight.j3o");
        // Material defaultMat = new Material( assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        f2.setMaterial(FenceMat);
        f2.setLocalTranslation(-7.8f, 0, 9.3f);
        Quaternion pitch90a = new Quaternion();
pitch90a.fromAngleAxis(FastMath.PI/2, new Vector3f(0,1,0));
/* Apply the rotation to the object */
f2.setLocalRotation(pitch90a);
        rootNode.attachChild(f2);

I have not tried to add anything else to the code yet.

Here is a picture just so you know what I’m trying to do:


And thanks all for the help.

You would add a rigid body control to the spatial and physics space.

https://wiki.jmonkeyengine.org/jme3/beginner/hello_physics.html

2 Likes

Solved, thanks!

1 Like