woratana Posted April 1, 2014 Share Posted April 1, 2014 I know this could be quite stupid question, but I couldn't figure out how So at the moment I have this ball bouncing around in the screen:http://codepen.io/designil/pen/tEwog/ How can I make the ball rotate naturally when they are bouncing around? Any hint would help Link to comment Share on other sites More sharing options...
valueerror Posted April 1, 2014 Share Posted April 1, 2014 in p2 physics you could (on collision) apply an angularForce depending on the current directon on the ball either cw or ccw... but with p2 you wouldn't use a rectangle as physics body but a circle.. so i guess applying forces wouldn't even be necessary.. Link to comment Share on other sites More sharing options...
d13 Posted April 1, 2014 Share Posted April 1, 2014 I'm not what the phaser syntax would be but here's the general formula: ball.rotation += ball.vx / ball.radius;But you'll also need to add a bit of gravity and friction before you see the kind of natural spin I think you're looking for. woratana 1 Link to comment Share on other sites More sharing options...
woratana Posted April 2, 2014 Author Share Posted April 2, 2014 Thank you d13 !! I tried your formula and it worked pretty good I will neglect the gravity stuff for now. You can see it in action herehttp://codepen.io/designil/pen/tEwog/ Link to comment Share on other sites More sharing options...
ZED Posted September 25, 2014 Share Posted September 25, 2014 Thanks, this is very useful and easy. Link to comment Share on other sites More sharing options...
Recommended Posts