There is a level created from static physical. objects (Box2d), at the level there is a dynamic object (ala the main character of the game), you need to make it so that it automatically constantly moves forward at one speed.

For example, if there is a hill, then it must rise and descend from it at the same speed as in a straight line and not fly up on the slopes as on springboards, i.e. go strictly along the line. Those. it must be a physical object, but that would not be acted upon by the acceleration / deceleration of gravity.

I do not quite understand how to do this with physics. I tried to use box2dBody->ApplyLinearImpulse and box2dBody->SetLinearVelocity , but this is exactly the impulse, but a constant speed is needed.

    1 answer 1

    Hey. For the constant movement of the hero, you need to add the following code in init ()

     this->scheduleUpdate(); 

    Then add the update method (float dt) , and in it change the position of the hero.

    Get the position of the hero:

     int _x = m_heroes->getPosition().x; int _y = m_heroes->getPosition().y; 

    And put in a new position:

     m_heroes->setPosition(_x, _y); 

    And add a hero to the scene:

     this->addChild(m_heroes)