- Home /
How do I Rotate a 2D object (sprite) so that it causes another to rotate?
I made a sprocket (a gear) sprite, and I have 2 sprockets in a scene. Both have polygonCollider2D's, as well as Rigidbody2D's. I set both to isKinematic, so they don't fall, and I set each of their angularDrag's to 0.
I basically want one sprocket to rotate, and when it rotates into the other, the other sprocket spins due to the collision.
I have a rotate script on one of the sprockets that just sets the angularVelocity of the sprocket so it rotates off the start.
Start() { rigidbody2D.angularVelocity = speed; }
What am I missing? because I have a ground below the sprockets, and if I turn off isKinematic, they both fall, and collide with each other at that point...but when one is rotating into the other, collision detection is not taking place.
You can just turn off gravity so they don't fall, so turn kinematic to off. Not sure how well a cog system will work with the standard settings. You might have to script your own. Like take one cog's angular velocity and apply it in reverse to the other cog, adjusting for the radius. That's math stuff... math stuff hurts my brain, so I can't be too helpful there. lol.
Yeah, well I've already tried turning is$$anonymous$$inematic off, then turning gravity off so they don't fall, however is$$anonymous$$inematic is used for stationary objects, and with it off, as well as gravity off, the rotation pushes the gears apart and they float away from each other.
That is definitely not what is wanted.
And I shouldn't have to script it myself. The collision system should handle it, but I must be missing something because they penetrate through each other ins$$anonymous$$d of colliding. $$anonymous$$aybe it's a PolygonCollider2D bug?
Thanks for trying to help though.
If you're wanting objects to react to physics you need kinematic ON. Of course they'll push away from each other as you have no forces holding the cogs together. That would also happen in real life. You could try making them child objects and set the parents to not move but I don't think you're going to be able to achieve anything decent without scripting it yourself. Another thing you could try is freezing the cogs' positions under the rigid body constraint settings.
Answer by FatalVitality · Feb 18, 2014 at 07:56 PM
Did you make sure they are at the same Layer so that they do not ignore one another?
Yes I did. I changed nothing with settings, or layers, because it defaults to all layers.
Answer by POLYGAMe · Feb 18, 2014 at 08:13 PM
Okay, I got it going fine without any code. Just freeze the position of the cogs and also freeze the rotation axis that you don't need. Make sure rigid bodies are set to NOT kinematic and turn off gravity and angular drag.
EDIT: Sorry, I meant NOT KINEMATIC. Fixed my answer :)
Rigidbody2D does not contain restraints since it's only on x/y axis. Are you using 3d rigidbody?
I'm working with 2D, 2D sprites, 2D PolygonColliders, 2D Rigidbodies
Ah, yeah, my bad. I was using 3D. I haven't used 2D. Surely you can still constrain the X/Y movement? Seems like a stupid thing to leave out...
Just had a play around with 2D colliders, they don't seem to react to each other's rotation at all. I was using circle colliders. You're probably better off just using 3D rigid bodies or scripting it, as you're right, it seems there's no way to lock off movement on the X/Y, so they'll just push apart. $$anonymous$$aking them children of base objects didn't work for me, either. $$anonymous$$aybe someone else who uses 2D colliders will be able to help, though.
Yeah, you just addressed all my issues i'm having lol no worries.
All I'm saying is that like the 3D version works, it should work in 2D as well, but it's almost like the collisions are either ignored, or like, the rigidbodies are sleeping for no apparent reason. Either way, I think this should be fixed (If it's a bug).
I also agree that 2D Rigidbodies should have x/y constraints as well.
Thanks for trying.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133938im_/https://answers.unity.com/themes/thub/images/avi.jpg)