I can't think of any sensible reason this will happen.
I am making a platformer, and want to get a more "oldschool" movement feeling - constant velocity, not slipping on angled surfaces, and simple jumps.
I tried a whole lot of ways to achieve that, none of them working decently (closest one being a wheel underneath the player, with the controls directly setting angular velocity).
Then I stumbled upon
this Box2DAS3 code that achieves what I want.
I did an exact port to my C++ code, and yet the friction isn't working correctly.
Even though the friction is set correctly to 0, 0.2 and 100, when in air, walking or standing for some time respectively, the
player never acts as if its friction is set to the specified values.
He doesn't stop immediately, and he slips on angle surfaces (no friction = 100).
Only if I comment both friction = 0 and 0.2, does it actually set it to 100.
Again, the function calls are being called correctly, and I can't see any reason for this behavior.
This is the relevant code, with std::couts to check if the calls are called:
Code:
if ((!keyboard[sf::Keyboard::A] && !keyboard[sf::Keyboard::D]) || (keyboard[sf::Keyboard::A] && keyboard[sf::Keyboard::D]))
{
stillTime += deltaTime;
m_body->SetLinearVelocity(b2Vec2(v.x * 0.9f, v.y));
}
else
{
stillTime = 0.0f;
}
if(!m_grounded)
{
std::cout << "0 " << rand() << "\n";
m_physicsFixture->SetFriction(0.0f);
m_sensorFixture->SetFriction(0.0f);
}
else
{
if (((!keyboard[sf::Keyboard::A] && !keyboard[sf::Keyboard::D]) || (keyboard[sf::Keyboard::A] && keyboard[sf::Keyboard::D])) && stillTime > 0.2f)
{
std::cout << "100 " << rand() << "\n";
m_physicsFixture->SetFriction(100.0f);
m_sensorFixture->SetFriction(100.0f);
}
else
{
std::cout << "0.2 " << rand() << "\n";
m_physicsFixture->SetFriction(0.2f);
m_sensorFixture->SetFriction(0.2f);
}
}
Thanks for any help.