Player Not Colliding With Boat [Solved]

One of my models is a ship, loaded in at the start of the program.



I add the ship in the Ship class’ init function.

[java] //Use Ship

spatial = GFX.sloop.clone();



//Add Physics

rigidBodyControl = new RigidBodyControl(

CollisionShapeFactory.createMeshShape(spatial), 0);





spatial.addControl(rigidBodyControl);

state.physicsSpace.add(rigidBodyControl);



rigidBodyControl.setPhysicsLocation(new Vector3f(0, -200, 20000));

Main.main.getRootNode().attachChild(spatial);[/java]

Ideally the boat will move when I’m finished, but it’s static for now, so it doesn’t roll away somewhere while I’m testing!



The player is added in its own init function.[java]

//Set Up Physics

sceneNode = new Geometry();

characterControl = new CharacterControl(new CapsuleCollisionShape(16, 32, 1), 1f);

characterControl.setPhysicsLocation(position);

sceneNode.addControl(characterControl);

state.physicsSpace.add(characterControl);

characterControl.setCcdMotionThreshold(1);

characterControl.setJumpSpeed(jumpSpeed);

characterControl.setGravity(gravity);

characterControl.setFallSpeed(fallSpeed);[/java]

The empty geometry in the player class is there to test whether it would start working once the CharacterControl had a spatial assigned to it. It didn’t work.



My problem is, despite all this code looking fine to me, the player doesn’t collide with the boat whatsoever. The boat (when mass>0) refuses to collide with the terrain too, but I’m assuming that’s just incompatibility between meshes. So how do I get the boat-player collisions to work?



If I need GImpactCollisionShape, could somebody provide an example on how to actually get Mesh data from my model spatial?



Also, my character routinely falls through the terrain, I’ve been tweaking the stepHeight value, is that the only fix?



Thanks,

JamieEclipse.

try add [java]state.physicsSpace.enableDebug(Main.main.getAssetManager());[/java] this will show the collision shapes, so you can more easily identify the problem. If your character falls through terrain, maybe the triangles of the terrain are too big, and stepheight does affect it yes, you don’t want a very small number for that.

wezrule said:
try add [java]state.physicsSpace.enableDebug(Main.main.getAssetManager());[/java] this will show the collision shapes, so you can more easily identify the problem. If your character falls through terrain, maybe the triangles of the terrain are too big, and stepheight does affect it yes, you don't want a very small number for that.
Thanks for the reply.
I've already enabled debug mode.
The ship's mesh shows up exactly like it should.
I can't see the character's mesh because the camera's inside it.
The terrain doesn't show anything for some reason, perhaps it's rendering behind the terrain's spatial? That doesn't really matter though I don't think, seeing as the terrain works already.

ok hmm, try these separately and see if any of them work:

  • move your boat with (setLocalTranslation), then add the rigidbody control
  • instead of calling CollisionShapeFactory.createMeshShape(spatial), 0), just put rigidBodyControl = new RigidBodyControl(spatial), 0);
  • Try add a simple collision shape instead

Setting the local translation didn’t seem to do anything. (I also left in the setPhysicsLocation call, is this what you wanted?)



Secondly, I assume you meant just new RigidBodyControl(0) then let it assign whatever it sees fit? This has exactly the same effect as the original code.



Then I used CollisionShapeFactory.createBoxShape(spatial) and that also did nothing, apart from introducing a weird glitch where the ship would disappear when you looked in a certain direction.

You must to set rigyd bodies’ gravity before added to physics space. Also, play with the character control’s stepHeight at its constructor.

glaucomardano said:
You must to set rigyd bodies' gravity before added to physics space. Also, play with the character control's stepHeight at its constructor.
I've tried stepHeight and the boat has no gravity at the moment.
Thanks for the reply though. :)

Okay, I’ve narrowed down the problem.



The boat’s collisions work right up until I call setPhysicsLocation.

Calling setLocalTranslation on the spatial doesn’t seem to work either.



If I give the boat mass, the problem seems to dissappear. Luckily, I want this rigidBodyControl to have mass anyway, but I will need static ones later.



So, any ideas on how to move a static RigidBodyControl?

Calling setLocalTranslation on the spatial doesn’t seem to work either.


http://i753.photobucket.com/albums/xx176/fistoffreeze/OhLawd.jpg

You shouldn't. Never call setLocalTranslation for physics objects.
glaucomardano said:
You shouldn't. Never call setLocalTranslation for physics objects.

Picture necessary?

I only tried that seeing as setPhysicsLocation causes the object to fail.

What do u mean about "setPhysicsLocation causes the object to fail. " ? It’s the only way to move a physics object properly.


Picture necessary?


yes :P

:open_mouth:

I’ve finally figured it out!

RigidBodyControl.setKinematic(true)!



@glaucomardano

Also, you use setLocalTranslation to move kinematic objects.

And by “causes the object to fail”, I mean if I have a RigidBodyControl with mass zero, and I try to move it with setPhysicsLocation, it stops colliding with the player. I’m guessing this is a glitch in the engine, but I can work around it with setKinematic.

1 Like

No jamie, glauco is right. You do not move RigidBodies with setLocalTranslation. That only works when you set them to kinematic in which case they are not influenced by the physics themselves but move along with the spatial.

1 Like