Actor jump -> check for ground contact -> jittering actor

I have a left/right side scroller game. The actor moves left/right and collides/interacts with other box2d fixtures.

I am moving the actor using:
Code:
actorBody->SetLinearVelocity(VelXdir,0)


every time step.



Now when I go to jump (jump button touched) I do:
Code:
actorBody->SetLinearVelocity(VelXdir,+20)

again every time step.



If actor is in midair (i.e. no contacts registered on feet) then I have to "push" actor back down using:
Code:
SetLinearVelocity(VelXdir,-10)




If any contacts register on actors feet then I do:
Code:
actorBody->SetLinearVelocity(VelXdir,0)




I assumed this was the best way to handle jumps but obviously not.

The actor jitters when near the ground. I assume it's because of small simulation errors (or maybe something else).
I log when a contact is made with actors feet and the ground and see a log of back and forth "contact"/"no contact"

Anyone have a better scheme to do actor jumping or know how to fix this issue?
If you make a C++ testbed example, I'll try to figure out what is causing the jitter.
Why push him down? Doesn't the gravity handle that?
And why set it to 0 when he lands? If there's no restitution the object should stop thanks to the physics engine.

As for jittering. Are you checking the contacts IsTouching() and IsEnabled()?
Quote:
Why push him down? Doesn't the gravity handle that?
And why set it to 0 when he lands? If there's no restitution the object should stop thanks to the physics engine.


I don't want actor to stop in the left/right running direction. Think of it like a horse running. To achieve constant running movement I pulse with SetLinearVelocity with parameters set to (VelXdir,0) every tick. Otherwise the object eventually comes to a halt. I have buttons to change the direction, stop, jump, etc.

I'm sure this is all caused by how I have it all set up ...


Quote:
If you make a C++ testbed example, I'll try to figure out what is causing the jitter.


The resources and classes for an example are attached (sorry my server is down atm else I would have sent all of it).

It shows the vibrating. It also shows that I aparantly am not checking collisions correctly based on the logging.
This is what a C++ testbed example looks like:
http://code.google.com/p/box2d/source/browse/trunk/Box2D/Testbed/Tests/VaryingRestitution.h
Quote:
This is what a C++ testbed example looks like:
http://code.google.com/p/box2d/source/b ... titution.h


hmmm ... *scratches head* ... I'm still trying to figure out how to convert the mini project I did this morning to what you request. I'll keep at it ...



Until then here is the xcode project all zipped up with build directory removed.

http://www.spectrid.com/box2dtestbed1copy.zip
Why not reuse the vertical velocity that the body has?

actorBody->SetLinearVelocity(VelXdir, actorBody->GetLinearVelocity().y)
I don't even need to check actor/ground contact anymore.

I feel like I wasted a lot of time for myself and others. Sorry.

A simple solution that I should have tried.

Thanks Trezker.

I'm gonna go hide under a rock now ...

Original thread: https://box2d.org/forum/viewtopic.php?t=5710