Jump to content

how do I ensure that the vehicle in unigine is always above the ground?


photo

Recommended Posts

I want to use the real-time location data of the vehicle and then drive the vehicle in the unigine scene to move, but how do I keep the vehicle in unigine above the ground at all times?

Is this implemented in code? Or through the associated unigine configuration? If it is a code implementation,can you give a C# code snippet?

Another problem is that I use real-time position data on vehicles or aircraft that may jump or wobble. Can I make a linear difference to solve this problem? Is there an API available in ungine?
Thanks!

Link to comment

Hello!

there is no ready-made function for sticking to the ground in the engine. because different objects are pressed against the ground in different ways.

The easiest way to press the object to the ground: you need to make a vertical raycast at the current position - get the point of intersection with the ground and change the current coordinates along the z axis to the received ones.

void DropToGround(Node node)
{
int intersection_mask = ~0; // intersection mask of terrain surface

dvec3 pos = node.WorldPosition;
dvec3 p1 = pos + dvec3.UP * 1000;
dvec3 p2 = pos - dvec3.UP * 1000;
WorldIntersectionNormal wi = new WorldIntersectionNormal();
Unigine.Object o = World.GetIntersection(p1, p2, intersection_mask, wi); // make vertical raycast to find ground height
if (o)
 pos.z = wi.Point.z;
node.WorldPosition = pos; // place object to the ground
// node.SetWorldDirection(node.GetWorldDirection(MathLib.AXIS.Y), wi.Normal, MathLib.AXIS.Y); // for conformal clamp 
}

for a more realistic movement of vehicles on the ground - you can use several raycasts. atleast three
- by three points make up the original basis,
- press the points to the ground
- make a new basis
- transfer the position and rotation from the old basis to the new one.
in this way, for example, the boat floats in the cpp_samples/water_global/simple boat

Link to comment
×
×
  • Create New...