Paddle Movement using Box2D
- by Anubhav Sharma
Hello everybody, I'm making a game like Arkanoid and to move the ship with mouse, I'm using the following code :
var mousex:int = costume.stage.mouseX;
if (mousex < paddleWidth/2)
mousex = paddleWidth/2;
else if (mousex > PhysiVals.STAGE_WIDTH - paddleWidth/2)
mousex = PhysiVals.STAGE_WIDTH - paddleWidth / 2;
var idealLocation:Point = new Point(mousex, ypos);
var directionToTravel:b2Vec2 = new b2Vec2((idealLocation.x -> costume.x) * PhysiVals.paddleSpeed, idealLocation.y-costume.y);
directionToTravel.Multiply(1 / PhysiVals.RATIO);
directionToTravel.Multiply(30);
body.SetLinearVelocity(directionToTravel);
Everything's going fine there! The paddle is moving the way it should! The problem is I want a little inclination towards the direction its moving and when it stops moving the angle of inclination should become zero. I tried playing with the angular velocity but I have no real idea how to do this! So Please help!