Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LukasSt · Apr 26, 2016 at 01:29 PM · 2dparentchildmovepositionangularvelocity

[MovePosition() on parent] + [angularVelocity = x on child] = problem. Unity 2D

Hi all I have a problem with making correct movement in my 2D environment: I have a script on parent object that basically does this:

 void Update () {
      if (child.GetComponent<Rigidbody2D>().angularVelocity == 0 ) {
           child.GetComponent<Rigidbody2D>().angularVelocity = 20;
      }
 }

It gives the child angular velocity, that is fine and dandy

Also i have another script attached to the parent object that pushed the object in a linear way like this:

 void Update () {
     if (activated && totalPush < 20) {
         gameObject.GetComponent<Rigidbody2D>().MovePosition(new Vector2(transform.position.x +2, transform.position.y));
         totalPush += 2;
     } else {
         activated = false;
     }
 }

I simplified both codes for easy understanding. My problem is that the child is rotating in a constant rotation when staying still, but when the parent starts to move (and of course child object moves with it) the child stops rotating, until parent stops, and then starts to rotate again. printing out child angular velocity to the console in update, gives a constant '20', even the brief moment it is not rotating (the rotation value in transform in the editor is not changing however, hence the absence of rotation)

Any ideas?

EDIT: I'm using Unity 5.4.0b13

EDIT 2: If I'm making the rotation script turn the parent object, then it working correctly (its moves and rotates at the same time)

Comment
Add comment · Show 2
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 toromano · Apr 26, 2016 at 02:20 PM 0
Share

$$anonymous$$aking child rigidbody kinematic might be helpful. By the way, you should not set angular velocity of a rigidbody directly.

avatar image LukasSt toromano · Apr 26, 2016 at 02:29 PM 0
Share

Sorry I forgot to mention, the child is also kinematic. I can't think of any other way of making it have a constant physical rotation (it is a gear in the game, that rotates constantly and pushes/bounces other non-kinematic objects around it with it's outside "teeth")

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LukasSt · Apr 27, 2016 at 01:30 PM

Well guys, I have created a new project to test some things out and I noticed that even in new project the rotation was being jittery on child when parent was moving (but it was at least moving a bit). So I tried different types of rotating the object (moveRotation for instance) and it then stopped rotating at all when parent was moving. I noticed this was happening due to child being kinematic, so i tried making it non-kinematic and attaching HingeJoint2D to child (connecting with the parent), and Ta-da! it started working, but the child kept slowing down when colliding with other non- kinematic objects (because it was non kinematic). Thats when i thought i should use hinge joint's Motor with big force, and it now works perfectly!

TL;DR : make child non-kinematic, connect child with parent with HingeJoint2D, and use Hinge Motors to rotate ignoring other objects (faking the kinematicness)

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Is it possible to prevent parent rigidbody physics from effecting children rigidbodies? 1 Answer

Instantiate as child Issue regarding 2D platformer melee system 0 Answers

Setting children position to Vector3.zero doesn't make them go to center of parent? 1 Answer

Child Not Keeping Up With Parent Translation 1 Answer


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