Terrain->Player: Stuck Collision Detection

Hi, I am new here and still a freshman in jme.

At the moment I program a little shooter-game with ground targets (npc mobs), which should move cleverly on a terrain.



In order that the mobs keep on ground and don’t fall through the terrain, i used the knowledge auf the 9. beginner tutorial (using Collision Shapes and Physics-Controls)

For the Heightmap Terrain i used the RigidBodyControl and for the character i used the Character-Control.



It works fine, that the Charakter keeps on ground and there is also a Terrain following, when the hill is not to steep. When the hill is to steep, the character stands still.



But if the npc-charakter still wants to move forward, because the movedirection has not changed, the game becomes very slow for some seconds (about 5 fps).

So I have to change the movedirection, if there is a steep hill. But how does the character control notice, that the hill is to steep for him?

I have already tried it with a Physics Collision Listener (for my Charakter-Control). But the Listener is triggered al the time, because the character stands on the ground and collide with the terrain all the time.

Well you can check if you actually move by storing your location and comparing it in the next update.

Where should I store the location?



I tried it in simpleUpdate and there I compared the last position with the current position.

.

First I set the WalkingDirection in the Init method at Vector3f(1f,0f,0f).

[java]public void simpleUpdate(float tpf) {

//checking if the char is stuck

if (charControl.onGround() && lastStep.x == golem3.getLocalTranslation().x && lastStep.y == golem3.getLocalTranslation().y) {

System.out.println("Stuck!");

charControl.setWalkDirection(new Vector3f(0f, 0f, 0.4f));

// Correction Method

}

if (charControl.getWalkDirection().x != 0 || charControl.getWalkDirection().z != 0) {

lastStep = golem3.getLocalTranslation().clone(); // Saving last position

}

}[/java]



Now there are two problems:

  1. The update method is called before the golem begins to move although I set the beginning walkingDirection in the Init Method. So the last step is stored before the golem move → golem don’t move.
  2. When the golem is moving and don’t stuck by a hill, the update method still detects a stuck, because the golem is to slow for the update method.

Basically like that yeah, if the check frequency is too high, just add a timer like “timer += tpf;” You should probably also correlate this to the walkDirection length, if its zero you are not supposed to move anyway.

Thank you. Ich will try it out.



But are to many timers bad for performance?

I will have many mobs. Each of them have different Movementspeeds and therefore a own timer.

No, how you think other games do this? You have to store and change the data somehow, computers are pretty fast and mostly its not the things that look like lots of work in code that actually use up many cpu cycles :wink:

Ok its working. At the moment the npc turns back, when he stucks.

However sometimes the game becomes still slow and freezes for a short time, when the character stocks and collide with the terrain.



Edit: Is it possible to use a Ghost Control for the mob - additional to the Character Control - to check, if the mob collides with the terrain?