Paddle Movement using Box2D
Posted
by
Anubhav Sharma
on Stack Overflow
See other posts from Stack Overflow
or by Anubhav Sharma
Published on 2011-01-03T14:10:14Z
Indexed on
2011/01/06
13:53 UTC
Read the original article
Hit count: 288
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!
© Stack Overflow or respective owner