Problem with character and ladder in a platform game. When the character collides with a ladder(through persist() in contactListener) i just set a boolean variable ( _onLadder:Boolean ) to true in the character class. The character class also have a update function which will be called every frame. So during update if the _onLadder is true it will call a method called climbUpTheLadder();
private function climbUpTheLadder():void
{
var idealLocation = new b2Vec2(_body.m_userData.x, _body.m_userData.y + (TRAVEL_SPEED * _climbingDirection));
var directionToTravel = new b2Vec2(idealLocation.x - _body.m_userData.x, idealLocation.y - _body.m_userData.y);
directionToTravel.Multiply(1 / Environment.RATIO);
directionToTravel.Multiply(Main.FRAME_RATE);
_body.SetLinearVelocity(directionToTravel);
}
till this everything works fine...
Now i need to keep the character in the xPos of the ladder whenever the character is climbing
so i just adds this _body.setXform() at the end of this climb function
_body.SetXForm(new b2Vec2(_ladderPosition.x, _body.GetPosition().y), 0);
Now the thing is even though the contact between character and ladder were removed, persist() in contact listener is keep
on calling. But i didnt call any of the function that will change the physics property of _body in contact listener i just sets a bool variable and handling everything in update function of character.
Need Help................
private function climbUpTheLadder():void
{
var idealLocation = new b2Vec2(_body.m_userData.x, _body.m_userData.y + (TRAVEL_SPEED * _climbingDirection));
var directionToTravel = new b2Vec2(idealLocation.x - _body.m_userData.x, idealLocation.y - _body.m_userData.y);
directionToTravel.Multiply(1 / Environment.RATIO);
directionToTravel.Multiply(Main.FRAME_RATE);
_body.SetLinearVelocity(directionToTravel);
}
till this everything works fine...
Now i need to keep the character in the xPos of the ladder whenever the character is climbing
so i just adds this _body.setXform() at the end of this climb function
_body.SetXForm(new b2Vec2(_ladderPosition.x, _body.GetPosition().y), 0);
Now the thing is even though the contact between character and ladder were removed, persist() in contact listener is keep
on calling. But i didnt call any of the function that will change the physics property of _body in contact listener i just sets a bool variable and handling everything in update function of character.
Need Help................