Simulated Rotation W/ Physics?

Hey, everyone!

I’m spawning images in an array then allowing the user to throw the image (its physic body is a circle) with a linear impulse, and I’m trying to get the image to rotate to simulate it actually being thrown instead of just flying around the screen without any kind of rotation.

I’ve tried messing around with the .rotation and changing it in an enterFrame function but it failed :\

Is there anything I can do to make the rotation random or allow the physics engine to take over?

Hi @antonio80,

Circular physics objects can, of course, rotate, but they won’t unless there’s some kind of force applied to them which will make them rotate (collision with another object or a force/impulse applied in code). You can do this in code using either of these:

https://docs.coronalabs.com/api/type/Body/angularVelocity.html

https://docs.coronalabs.com/api/type/Body/applyTorque.html

And then, if you want the body to natually slow down its rotation after a time, instead of spinning endlessly, you should apply some angular damping:

https://docs.coronalabs.com/api/type/Body/angularDamping.html

Hope this helps,

Brent

Thanks man! Helped out a lot!

Hi @antonio80,

Circular physics objects can, of course, rotate, but they won’t unless there’s some kind of force applied to them which will make them rotate (collision with another object or a force/impulse applied in code). You can do this in code using either of these:

https://docs.coronalabs.com/api/type/Body/angularVelocity.html

https://docs.coronalabs.com/api/type/Body/applyTorque.html

And then, if you want the body to natually slow down its rotation after a time, instead of spinning endlessly, you should apply some angular damping:

https://docs.coronalabs.com/api/type/Body/angularDamping.html

Hope this helps,

Brent

Thanks man! Helped out a lot!