SpiderPig Posted May 22 Share Posted May 22 Run this code and use the arrows keys to move the player and move to intercept the box on the left. There's a few bugs here: After the first collision - "Collison Detected" is still printed to the console even after you move away from the box position, normal & speed are never above zero I've only noticed these issues when using COLLISION_TRIGGER as the collision type. So far normal collisions seem fine. #include "UltraEngine.h" using namespace UltraEngine; class MyComponent : public Component { private: public: virtual void Collide(shared_ptr<Entity> collidedentity, const Vec3& position, const Vec3& normal, const float speed) { Print(WString((float)Millisecs() / 1000.0f) + " : Collision Detected : " + WString(position) + " : " + WString(normal) + " : " + WString(speed)); } }; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 2, -6); camera->SetDebugPhysicsMode(true); //Create light auto light = CreateDirectionalLight(world); light->SetRotation(35, 35, 0); light->SetColor(3); auto trigger = CreateBox(world, 4); trigger->SetPosition(-4, 3, 0); trigger->SetCollisionType(COLLISION_TRIGGER); trigger->AddComponent<MyComponent>(); auto floor = CreateBox(world, 100.0f, 0.1f, 100.0f); auto box = CreateCylinder(world, 0.5f, 1.8f); box->SetCollisionType(COLLISION_PLAYER); box->SetMass(1.0f); box->SetPosition(0, 0.05, 0); box->SetCollider(CreateCapsuleCollider(0.5f, 1.8f)); auto joint = CreateKinematicJoint(Vec3(), box); joint->SetMaxForce(1000); joint->SetMaxTorque(1000); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { auto pos = box->GetPosition(true); auto speed = 0.25f; if (window->KeyDown(KEY_UP)) { pos.z += speed; } if (window->KeyDown(KEY_DOWN)) { pos.z -= speed; } if (window->KeyDown(KEY_LEFT)) { pos.x -= speed; } if (window->KeyDown(KEY_RIGHT)) { pos.x += speed; } joint->SetPose(pos, Vec3()); world->Update(); world->Render(framebuffer); } return 0; } 1 Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted June 11 Solution Share Posted June 11 FIXED! 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted June 11 Author Share Posted June 11 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.