Vulcan Posted August 24, 2014 Share Posted August 24, 2014 Have anyone experienced that the player is vibrating after turning when using SetInput() ? How do I fix this issue? In App->Start(): ... // Create the player entity = Pivot::Create(); entity->SetPosition(Vec3(0.0f, 0.0f, 0.0f)); entity->SetRotation(Vec3(0.0f, 0.0f, 0.0f)); entity->SetMass(1.0f); entity->SetPhysicsMode(Entity::CharacterPhysics); // Load model model = Model::Load("Models/Characters/Barbarian/barbarian.mdl"); model->SetParent(entity); ... App->Loop(): ... // Calculate new angle float angle = 0.0f; float a = entity->GetRotation().y; float b = (window->KeyDown(Key::D2) - window->KeyDown(Key::D1)) * 10.0f; //turn speed angle = a + b; // Turn player but this causes vibration looking effect. Hmm?? // Look at the edge of the sword after stopped turning. entity->SetInput(angle, 0.0f); ... Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 24, 2014 Author Share Posted August 24, 2014 After some debugging I found that changing from Sync(false) to Sync(true) then the problem goes away. But should I force users to use VSync? Or is there a better way for those who get higher 60 FPS ? Quote Link to comment Share on other sites More sharing options...
nick.ace Posted August 24, 2014 Share Posted August 24, 2014 This is what is probably going on. You are grabbing the entity's rotation before the next physics update. Physics I think is run on a separate thread, so by forcing VSync(), you are allowing more time for the physics to update, but this may not always be the case. You'll probably get better results if you put your methods in the UpdatePhysics function. However, I think you'll need to place this script onto an entity because I don't think that the App "class" has it, but I could be wrong. Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 25, 2014 Author Share Posted August 25, 2014 After some testing with UpdatePhysicsHook I still get this Z-rotating jittering when using SetInput(). I really don't know why but I am starting to wonder if it could be that it is only the model that are jittering but not the entity? Or should I just abandon the idea of using SetInput() ? Registering the hook: entity->AddHook(Entity::UpdatePhysicsHook, (void*)UpdatePhysicsHook); Updating physics: entity->SetInput(entity->GetRotation().y + 10.0f*window->KeyDown(Key::D1), 10.0f*window->KeyDown(Key::D2)); Quote Link to comment Share on other sites More sharing options...
cassius Posted August 25, 2014 Share Posted August 25, 2014 Sometimes parenting can cause flicker during lateral movement. In my 3rd person game I solved this by removing parenting and just placing the character in the entity position in the main loop. But maybe that's not the same as your problem. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Vulcan Posted August 25, 2014 Author Share Posted August 25, 2014 Thank you! This solved my jitter problem. I did remove the parenting and changed my code to this if anyone are interested. entity->SetInput(angle, move); model->SetPosition(entity->GetPosition()); if (b > 0.01f || b < -0.01f) model->SetRotation(entity->GetRotation()); It might not be perfect but this seems to work. Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 25, 2014 Author Share Posted August 25, 2014 Minor change: model->SetRotation(0.0f, entity->GetRotation().y + 180.0f, 0.0f); 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.