Hello everyone, i’m creating a simple game but i’m having a problem, I have wrote this code as an example of what i want to do:
physics = require ("physics") physics.start( ) ball = display.newImageRect("Ball.png", 15, 15, {x=0,y=0}) physics.addBody(ball, 'dynamic' , {radius=7.5,bounce=0.8}) local downhill = display.newRect( 130, 130, 1500, 150 ) physics.addBody( downhill,"static" ) downhill.rotation = 2
In this code a ball goes downhill and you can see it going down but the image doesn’t rotate, to get the effect of rotating i must put:
ball:applyAngularImpulse( 0.01 )
How can i get the same effect without doing that? I’m making a game where you basically launch a ball to break some brick and can’t make the ball image rotate. Thanks in advance!
XeduR
October 4, 2019, 9:43pm
2
You need to give the ball a friction value that isn’t 0. With 0 friction, it simply glides. Giving it a friction of even 0.01 will force it to rotate.
Also, when you are creating the imageRect, if you want to give the object specific x and y coordinates, you need to do so via other means, e.g.
ball.x, ball.y = 20, 40
That table you’ve added at the end of your newImageRect function doesn’t do anything and it is just ignored by the function.
Thanks, i’ve tried this solution but i was always writing after the physics.addBody this
ball.friction = 0.01
instead of something like:
physics.addBody(ball, 'dynamic' , {radius=7.5,bounce=0.8,friction=0.01})
now, for some reason i realized i was doing it wrong, it works correctly, thanks again!