Jump to content

[SOLVED] Detect contact with water more precise(V2.4.1.)


photo

Recommended Posts

Hi there!

I'm implementing a routine to display an affect when a flying object crash on water (ObjectWaterGlobal node) and what a I have done is working, but not in all the test I do.

 

void AirVehicle::hitTheFloor()
{
  double z1 = mNodeBodyGood->getNode()->getWorldPosition().< + 1.0;
  double z2 = mNodeBodyGood->getNode()->getWorldPosition().< - 1.0;
  
  Unigine::Math::Vec3 position = mNodeBodyGood->getNode()->getWorldPosition();
  Unigine::WorldIntersectionPtr intersection = Unigine::WorldIntersection::create();
  Unigine::Vector<Unigine::NodePtr> exclude;
  exclude.append(mNodeBodyGood->getNode());
  std::vector<Unigine::NodePtr> nodeArray = util::UnigineUtils::collectAllChildren(mNodeBodyGood->getNode());
  for (int i = 0; i < (int)nodeArray.size(); i++)
  {
    exclude.append(nodeArray.at(i));
  }
  Unigine::ObjectPtr floor = Unigine::World::get()->getIntersection( Unigine::Math::Vec3(position.x, position.y, z1),
                                                                    Unigine::Math::Vec3(position.x, position.y, z2),
                                                                    0xFF, exclude, intersection);
  if (floor.get() != nullptr)
  {
    if (floor->getType() == Unigine::Object::OBJECT_TERRAIN)
    {
      ///Do Something
    }
    else if (floor->getType() == Unigine::Object::OBJECT_WATER_GLOBAL)
    {
      ///Do Something
    }
  }
}

To detect the collision with the ObjectWaterGlobal I'm calculating a intersection of the falling object with anything around 1 meter over and above the object.

But some times the intersection is empty and the collision is not detected.

Is there another way to detect the collision with water in a more precise way?

 

Edited by Gmarquez
Link to comment
  • Gmarquez changed the title to Detect contact with water more precise(V2.4.1.)
  • Gmarquez changed the title to [SOLVED] Detect contact with water more precise(V2.4.1.)
×
×
  • Create New...