I looked at the tutoral and implemented the sourcecode from Lession9 (moving bike) into my BaseGame - Water implementation. So I did this:
TerrainBlock tb with a custom HeightMap to create a river (digged the terrain)
WaterRenderPass
lowered TerrainBlock, so it looks like a river
integrated the bike from Lesson9-Tut
I now want the bike to only move on the river! At the moment it is “stuck” to the TerrainBlock tb:
//make sure that if the player left the level we don't crash. When we add collisions,
//the fence will do its job and keep the player inside.
float characterMinHeight = tb.getHeight(player
.getLocalTranslation())+agl; //if agl is deleted the player is lower
if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
player.getLocalTranslation().y = characterMinHeight;
}
//get the normal of the terrain at our current location. We then apply it to the up vector
//of the player.
tb.getSurfaceNormal(player.getLocalTranslation(), normal);
if(normal != null) {
player.rotateUpTo(normal);
}
I had 2 thoughts about it and need some perfect advice ;)
First: Stick to the TerrainBlock tb and write a function, that if the height is lower than a value the bike is allowed to move there
Second: Stick to the WaterQuad or make another quad underneath it and use this...
I think the first one is better. Do you think this could work???
You could compare the height of the terrain (at a given point) with the height of the water, if the terrain height is greater than the water don't move on to it…
I wrote this test and it gives me an output, when the player is moving on the water! So this totally works!
//only move on the water
Vector3f transVec2 = new Vector3f(player.getLocalTranslation());
Vector3f heightTerrain = new Vector3f(0,0,0);
tb.localToWorld(transVec2, heightTerrain);
if (heightTerrain.y < waterEffectRenderPass.getWaterHeight()){
System.out.println("Bike is on the water");
System.out.println("Hight terrain local to world: " + heightTerrain.y);
// System.out.println("Hight water: " + waterEffectRenderPass.getWaterHeight());
}
Now that I have the right if-loop I have to tell to only be allowed to move when the value of the current pos. of the player is < 0.0 (water)!!
Do I have to write my owm class for this? Or is it possible to easily tell in the update-method?
Everything is working at the moment! Thanks for all of your replies!
Now I have to get a preciser result!! I am using a BoundingBox for the model. So it gives me a collision way to soon. Especially on the side of the bike! Should I use a BoundingVolume instead? Or is there another possible way?