Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by matthewhoyes18 · Feb 18, 2014 at 06:13 PM · 2drotate

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image POLYGAMe · Feb 18, 2014 at 07:21 PM 0
Share

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.

avatar image matthewhoyes18 · Feb 18, 2014 at 07:33 PM 0
Share

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.

avatar image POLYGAMe · Feb 18, 2014 at 08:04 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image matthewhoyes18 · Feb 18, 2014 at 08:09 PM 0
Share

Yes I did. I changed nothing with settings, or layers, because it defaults to all layers.

avatar image
0

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 :)

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image matthewhoyes18 · Feb 18, 2014 at 08:30 PM 0
Share

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

avatar image POLYGAMe · Feb 18, 2014 at 08:33 PM 0
Share

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...

avatar image POLYGAMe · Feb 18, 2014 at 08:35 PM 0
Share

Try using 3D rigid bodies? They work :)

avatar image POLYGAMe · Feb 18, 2014 at 08:47 PM 0
Share

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.

avatar image matthewhoyes18 · Feb 18, 2014 at 09:03 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

newbie 2d simple sprite rotation 1 Answer

Unity 2D Rotate Problem! 1 Answer

[2D] How do you rotate a 2D sprite left and right with C#? 2 Answers

How do I make one GameObject Point Towards another GameObject in 2D? 1 Answer

Problem with rotated colliders 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges