Jump to content

[SOLVED] Problem using ObjectWater::getHeight().


photo

Recommended Posts

Hi all,

In the attached example the objective is to keep the cube over the water surface. The problem is there is not a visual matching between the height returned by ObjectWater::getHeight() and the visual representation.

 

It's something wrong in node expression? It's an ObjectWater problem?

 

Thanks.

water_height.cpp

water_height.world

Link to comment
  • 2 weeks later...

Hi Ivan,

 

ObjectWater::getHeight gets current offset of a given point relative to the water surface, to correct this offset, you need to add a negative value of offset:

{	
	Node n= getNode();
	ObjectWater w= class_cast("ObjectWater", engine.editor.getNodeByName("ocean2"));
	
	dvec3 pos= n.getWorldPosition();
	
	float h= w.getHeight(pos);
	
	pos.z -= h;
	
	n.setWorldPosition(pos);
}
Link to comment
×
×
  • Create New...