Jump to content

Vibrating player


Vulcan
 Share

Recommended Posts

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);
...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

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.

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

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...