I have a scene init with physics and i have a character sprite with a physics body, then I have a static ground sprite with a physics body. That all works fine so my next step was to move my character. Now I assumed that if I just updated my characters X position the character would move and stay on the ground but if the ground drops off the character does not drop it just floats, how do i move my character sprite and have it stay on the ground at all times? The code for my update function is below
void LevelOne::update(float delta)
{
if (mJoystick->isActive())
{
Vec2 scaledVelocity = mJoystick->getVelocity() * 240;
Vec2 updatedPosition = Vec2(mCharacter->getPosition().x + scaledVelocity.x
* delta, mCharacter->getPosition().y);
mCharacter->setPosition(updatedPosition);
if (mJoystick->getVelocity().x < 0)
{
mCharacter->setFlippedX(false);
}
else
{
mCharacter->setFlippedX(true);
}
}