Moving Object on Water

Hi everyone,

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???

Thanks RapidM

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…

Hi...

I wrote a little helper to get the values of terrain at current player location and of the water:

[code]  if (tb.getHeight(player.getLocalTranslation()) > waterEffectRenderPass.getWaterHeight()){
                         System.out.println("Hight terrain: " + tb.getHeight(player.getLocalTranslation()));
                         System.out.println("Hight water: " + waterEffectRenderPass.getWaterHeight());                      
        }[/code]

The Water is always 0.0

The problem is with the terrain. It is always greater than 0.0!!!!  Here is an example of the current hight, when moving on the "river"parts:

[code]Hight terrain: 1.9594187
Hight water: 0.0
Hight terrain: 2.002534
Hight water: 0.0
Hight terrain: 2.0395582
Hight water: 0.0
Hight terrain: 2.1039238
Hight water: 0.0
Hight terrain: 2.1700764
Hight water: 0.0
Hight terrain: 2.2338827
Hight water: 0.0
Hight terrain: 2.2759264
Hight water: 0.0
Hight terrain: 2.2703683
Hight water: 0.0
Hight terrain: 2.2648332
Hight water: 0.0
Hight terrain: 2.3054295
Hight water: 0.0
Hight terrain: 2.423802
Hight water: 0.0
Hight terrain: 2.5419927
Hight water: 0.0
Hight terrain: 2.6600072
Hight water: 0.0
Hight terrain: 2.777801
Hight water: 0.0
Hight terrain: 2.8954182
Hight water: 0.0
Hight terrain: 3.012844
Hight water: 0.0[/code]

I moved the heightMap -9 on the y-axis. Can I just cull the terrain where all values from the y-axis are <= 0?

IIRC, the getHeight function just returns the interpolated heightmap value in local space.

Try doing tb.localToWorld on it to get a more useful value.



Not sure that's right and can't check right now, but I give it a go.

I think you could just subtract the Y value of your terrain from the returned height…



(or in your case, subtract 9)

Thanks for the replies!



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?

Thanks  (nooby questions*g*)!!!

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?



Thanks