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
1
Question by Hazlo · Jul 27, 2014 at 08:43 AM · 2drigidbody2dsliderjoint2d physics

Unity 4.5.2p2 SliderJoint2D broken or different?

We have a quite big 2D game at around 80% of its development completed (now it has 81 scenes). It was working fine on Unity 4.3, but we needed to upgrade to Unity 4.5 due to a pair of its new features. The problem is that all the prefabs that were sliding platforms where a ball could bounce over them (using physics2D) now are broken. They use a Slider Joint 2D with motor and limits to make them move horizontally or vertically over the scene (a custom script makes them switch direction when a limit is reached). They are connected to a point in the scene ("Connected Anchor") to make a line of movement. Now they stop well before a limit is reached and if we look at their gizmo, the limits are still well calculated but now they seem to move with the object! We even tried to update the anchor in FixedUpdate to keep the limits on their place, but it's a no-no.

So, might it be that SliderJoint2D behaves different than on 4.3? Or could it be broken in this build? Is some other developer using it in a similar way and noticed the problem?

Here is the code that calcs the limits (please notice that it worked flawlessly under 4.3):

 void CalcSliderData()
 {
     JointTranslationLimits2D limits;
     RaycastHit2D hit;
     Vector2 startPos;
 
     // Calc/load positions and limits
     mSliderJoint.connectedAnchor = this.transform.position;
     limits = mSliderJoint.limits;
     if (Direction == MoveDirection.Horizontal)
     {
         // (cast ray rightmost and calc max limit)
         startPos = this.transform.position;
         startPos.x += this.renderer.bounds.size.x / 2 + 0.01f;
         hit = Physics2D.Raycast(startPos, Vector2.right,
             float.PositiveInfinity, 1 << 10);
         if (hit.collider != null)
         {
             limits.max = (hit.point - startPos).x - BorderCollisionSensitivity;
         }
         else
         {
             mSliderDataIsOK = false;
             print("ERROR: MovingWallHoriz " + this.name +
                 " can't find its rightmost limit!");
             return;
         }
         // (cast ray leftmost and calc min limit)
         startPos = this.transform.position;
         startPos.x -= this.renderer.bounds.size.x / 2 + 0.01f;
         hit = Physics2D.Raycast(startPos, -Vector2.right,
             float.PositiveInfinity, 1 << 10);
         if (hit.collider != null)
         {
             limits.min = (hit.point - startPos).x + BorderCollisionSensitivity;
         }
         else
         {
             mSliderDataIsOK = false;
             print("ERROR: MovingWallHoriz " + this.name +
                 " can't find its leftmost limit!");
             return;
         }
         mSlideUpperPos = mSliderJoint.connectedAnchor;
         mSlideUpperPos.x += limits.max;
         mSlideBottomPos = mSliderJoint.connectedAnchor;
         mSlideBottomPos.x += limits.min;
     }
     else
     {
         // (cast ray upwards and calc max limit)
         startPos = this.transform.position;
         startPos.y += this.renderer.bounds.size.y / 2 + 0.01f;
         hit = Physics2D.Raycast(startPos, Vector2.up,
             float.PositiveInfinity, 1 << 10);
         if (hit.collider != null)
         {
             limits.max = (hit.point - startPos).y - BorderCollisionSensitivity;
         }
         else
         {
             mSliderDataIsOK = false;
             print("ERROR: MovingWallVert " + this.name + 
                 " can't find its upper limit!");
             return;
         }
         // (cast ray downwards and calc min limit)
         startPos = this.transform.position;
         startPos.y -= this.renderer.bounds.size.y / 2 + 0.01f;
         hit = Physics2D.Raycast(startPos, -Vector2.up,
             float.PositiveInfinity, 1 << 10);
         if (hit.collider != null)
         {
             limits.min = (hit.point - startPos).y + BorderCollisionSensitivity;
         }
         else
         {
             mSliderDataIsOK = false;
             print("ERROR: MovingWallVert " + this.name +
                 " can't find its lower limit!");
             return;
         }
         mSlideUpperPos = mSliderJoint.connectedAnchor;
         mSlideUpperPos.y += limits.max;
         mSlideBottomPos = mSliderJoint.connectedAnchor;
         mSlideBottomPos.y += limits.min;
     }
     mSliderJoint.limits = limits;
     mSliderDataIsOK = true;
 }
 
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 incorrect · Jul 27, 2014 at 09:11 AM 0
Share

Can you show the part of script which deter$$anonymous$$es limits?

avatar image Hazlo · Jul 27, 2014 at 09:51 PM 0
Share

Of course. You can find it in the question (I edited it to add the code). Thank you!

1 Reply

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

Answer by Hazlo · Jul 28, 2014 at 07:09 AM

Ok ok, I'll answer to my own question: from Unity 4.5, motors are REVERSED. So the speed needs to change the sign to be the same as before, AND the limits need to switch. So, to put it easy (of course that won't be final code!), if you add these lines:

 float a = limits.min;
 limits.min = -limits.max;
 limits.max = -a;
 

before "mSliderJoint.limits = limits", everything is back to what it was in 4.3. Woah, what a change! It's just like if I take my car to the mechanic to change oil and when I get it back, from now on the Reverse is forwards and Drive is Reverse!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2d Object Increases in Speed with Each Collision 0 Answers

Character Joints, twist and swing 0 Answers

Rigidbody2D x velocity not moving unless placed in FixedUpdate 1 Answer

Remove Drag/Friction 1 Answer

(2D) character jumping problem [is grounded detection, rigidbody2d] 2 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