Urho3D Wiki
Advertisement

Urho3D integrates the Bullet physics engine: http://bulletphysics.org/

Each node in Urho can be set up to be a static (non moving) or dynamic (moved by physic and gravity) physical object:

RigidBody* body=node->CreateComponent<RigidBody>();
body->SetMass(50.0); // set to 0 (default) for static objects
body->SetLinearDamping(0.2f); // air friction body->SetAngularDamping(0.2f); // rotaion damping
body->SetFriction(0.6); // friction with other objects (like the ground)
// optional, some actions like raycast can be set to only be on one layer. In USP the play is on layer 1 and everything else on level 2. body->SetCollisionLayer(2); // box shaped collider, the first vector is the sice and the second an optional positon offset CollisionShape* shape=node->CreateComponent<CollisionShape>();
shape->SetBox(Vector3(0.7,1.47,0.7),Vector3(0,1.47/2,0)); // could also be a triangle mesh: //shape->SetTriangleMesh(cache->GetResource<Model>("level1.mdl")); // or a convex hull or one of the other types //shape->SetConvexHull(cache->GetResource<Model>("Models/rock.mdl"));

Note: triangle mesh on triangle mesh collisions are disabled per default. See PhysicsWorld::SetInternalEdge(bool enable) http://urho3d.github.io/documentation/1.32/class_urho3_d_1_1_physics_world.html.

Example of an physical raycast

PhysicsRaycastResult result;
Vector3 pos(-120-Random(100.0f),100,-70-Random(100.0f));
Ray ray(pos,Vector3(0,-1,0)); // the given vector is the direction
physical_world->SphereCast(result,ray,2,100); // a sphere cast has a volume
if(result.distance_<=1000) // if hit something
pos=result.position_+Vector3(0,5,0);
Advertisement