SetSweptCollisionMode

This function sets the swept collision mode of an entity. Entities with swept collision enabled will have more accurate collisions that are more computationally expensive to process. Use this for small and thin objects if you have problems with them going through other entities.

Syntax

Parameters

Example

#include "Leadwerks.h"

using namespace Leadwerks;
Entity* entity1 = NULL;
Entity* entity2 = NULL;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(15, 0, 0);
camera->Move(0, 0, -8);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

//Create the ground
Model* ground = Model::Box(10, 0.1, 10);
ground->SetColor(0.0, 1.0, 0.0);

//Create a shape
Shape* shape = Shape::Box(0, 0, 0, 0, 0, 0, 10, 0.1, 10);
ground->SetShape(shape);
shape->Release();

//Create a model
entity1 = Model::Box();
entity1->SetScale(1, 0.1, 4);
entity1->SetColor(0.0, 0.0, 1.0);
entity1->SetPosition(-2, 5, 0);
entity1->SetMass(1);
entity1->AddForce(0, -1000, 0);

//Create a shape
shape = Shape::Box();
entity1->SetShape(shape);
shape->Release();

//Create a second model
entity2 = entity1->Instance();
entity2->SetPosition(2, 5, 0);
entity2->SetSweptCollisionMode(true);
entity2->AddForce(0, -1000, 0);

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Time::Update();
world->Update();
world->Render();

context->SetBlendMode(Blend::Alpha);
context->DrawText("entity1 swept collision mode: " + String(entity1->GetSweptCollisionMode()), 2, 2);
context->DrawText("entity2 swept collision mode: " + String(entity2->GetSweptCollisionMode()), 2, 22);
context->Sync();

}
return 0;
}