SpiderPig Posted July 19, 2018 Posted July 19, 2018 #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } float jointpos = 1; bool wireframe = false; Joint* joint; Entity* parent; bool App::Start() { window = Leadwerks::Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -4); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); parent = Model::Box(); parent->SetColor(0.0, 0.0, 1.0); Entity* child = Model::Box(); child->SetColor(1.0, 0.0, 0.0); child->SetShape(Shape::Box()); child->SetMass(1); child->SetFriction(0, 0); child->SetGravityMode(true); joint = Joint::Slider(0, 0, 0, 0, 1, 0, child, parent); joint->EnableLimits(); joint->SetLimits(-3, 1); Model* mdl = Model::Box(); mdl->SetScale(10, 0.1, 10); mdl->SetPosition(0, -2, 0); Shape* shp = Shape::Box(); mdl->SetShape(shp); return true; } bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; if (window->KeyHit(Key::F3) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F4) == true) { camera->GetDebugEntityBoxesMode() == true ? camera->SetDebugEntityBoxesMode(false) : camera->SetDebugEntityBoxesMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } if (window->KeyDown(Key::Up)) { parent->Move(0, 0, 0.1); } if (window->KeyDown(Key::Down)) { parent->Move(0, 0, -0.1); } if (window->KeyDown(Key::Left)) { parent->Move(-0.1, 0, 0); } if (window->KeyDown(Key::Right)) { parent->Move(0.1, 0, 0); } joint->SetAngle(jointpos); if (window->KeyHit(Key::Space)) { if (!joint->MotorEnabled()) { joint->EnableMotor(); } else { joint->DisableMotor(); } } Leadwerks::Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawText("Target position: " + String(jointpos), 0, 0); context->DrawText("Current position: " + String(joint->GetAngle()), 0, 20); context->DrawText("Motor enabled: " + String(joint->MotorEnabled()), 0, 40); context->SetBlendMode(Blend::Solid); context->Sync(); return true; } Using the arrows keys to move the sliders parent around you can see that the child takes time to realign itself. Is it possible to stop this delay? Quote
Solution Josh Posted July 19, 2018 Solution Posted July 19, 2018 If you use the positioning commands like Move, SetPosition, etc. you are breaking the physics simulation that frame. Instead, you can create a a kinematic joint and use that to precisely control an object's position: https://www.leadwerks.com/learn?page=API-Reference_Object_Joint_Kinematic https://www.leadwerks.com/learn?page=API-Reference_Object_Joint_SetTargetPosition Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted July 19, 2018 Posted July 19, 2018 Do I get the trophy marked? I answered the question! ? Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted July 19, 2018 Posted July 19, 2018 10 hours ago, Josh said: ¿Obtengo el trofeo marcado? ¡Respondí la pregunta! ? :D 1 Quote
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.