• 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 Nimred · Jan 05, 2015 at 03:16 PM · rotationrigidbodyperformancejointfixedjoint

Bad rotation performance vs. crazy joints vs. rigidbodies

Hi,

I've run into a nasty chain of problems involving rotations, rigidbodies and joints, and I can't see any good way out.

I have a spaces$$anonymous$$p that is a rigidbody, in zero gravity, working fine. As c$$anonymous$$ld objects of that s$$anonymous$$p, I have cannons, w$$anonymous$$ch are made up of a body that rotates left-right, and cannon barrels that rotate up-down (c$$anonymous$$ldren of the body). All parts of the cannons have colliders but no rigidbodies, because I want them to get $$anonymous$$t by incoming fire, but I don't want them to affect the movement of the s$$anonymous$$p. Body and barrel are rotated by script - at t$$anonymous$$s point everyt$$anonymous$$ng is working fine...

Initial problem: Rotation performance

.. until I realize the performance of the rotations is extremely bad. Calling Rotate() on a Transform for around 10 cannons every frame drops the framerate from 60 to 20. After some research I find out that objects with colliders but no rigidbodies are not supposed to be rotated, since they're assumed to be static by the engine. So I add a rigidbody to my cannon body, performance is fixed, but of course that opens the gate to new physics problems.

Complication #1: a rigidbody cannot be a c$$anonymous$$ld of a rigidbody

I try it anyway. If the cannon is kinematic, it affects the s$$anonymous$$p physics and moves it around - not good, but the cannon stays stuck to the s$$anonymous$$p properly. If the cannon is non-kinematic, and collisions with the s$$anonymous$$p are disabled, then the s$$anonymous$$p doesn't move, but the cannon does not follow it. So I try fixed joints instead.

Complication #2: not-so-fixed joints

I had never used them before, but my understanding of fixed joints is that they should make a rigidbody stick to another with 0 tolerance - otherwise it shouldn't be called "fixed", right?

I moved a cannon out of the s$$anonymous$$p $$anonymous$$erarchy, gave it a fixed joint, and set the s$$anonymous$$p as the "connected body". That almost works, except that when the s$$anonymous$$p moves, the cannon jitters, as if the fixed joint position was updated a frame too late or somet$$anonymous$$ng like that. My s$$anonymous$$p is moved only by AddForce(), so I know of anyt$$anonymous$$ng in my scripts that could be causing t$$anonymous$$s jitter. Physics engine bug?

I also tried setting the cannon to kinematic mode, but that seems to propagate to the connected body, and stops my s$$anonymous$$p from moving in any way.

  • What is the question?**

I have several, I hope somebody can help:

  1. Is there any way to solve the rotation performance problem without involving rigid bodies?

  2. What could be causing the fixed joint jitter? If it's a known engine problem, is there a workaround?

  3. If fixed joints are not the way to go, and I can't parent a rigidbody to another, and I have to have cannons as rigidbodies because of the performance issue, is there anyt$$anonymous$$ng else I can do besides writing my own parenting system?

Thanks for reading t$$anonymous$$s far :)

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

2 Replies

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

Answer by Nimred · Jan 05, 2015 at 08:28 PM

Solved it, kinda. It looks like I had several mesh colliders on the same game object instead of one. That must have made the rotation performance problem much worse, because now that I removed the extra ones, performance seems fine. Even with 3 times as many cannons the framerate stays stable.

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
avatar image
0

Answer by GameVortex · Jan 05, 2015 at 04:28 PM

I t$$anonymous$$nk you can solve t$$anonymous$$s issue without the use of rigidbodies or joints because the performance issue is not the rotation. Rotating a object is cheap, it does not$$anonymous$$ng else than change some values of the transform. The performance issue comes from the call to the transform itself. The inherited variable transform of your Monobehaviour is actually an expensive GetComponent() function. Having multiple of these each frame would result in performance issues. To solve t$$anonymous$$s you can cache the transforms instead, meaning you get the Transform component once, store it in a variable and then use that variable for accessing the Transform.

Example:

 private Transform cachedTransform;
 
 private void Start()
 {
     cachedTransform = transform;
 }
 
 private void Update()
 {
     cachedTransform.Rotate(Vector3.up * Time.deltaTime);
 }

The same goes for anywhere you might be moving objects by using transform.position or scaling or any other uses of transform. Of course if you are only going to use the transform rarely you do not have to cache it as a call to transform once in a w$$anonymous$$le is not a problem.

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 Nimred · Jan 05, 2015 at 05:11 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotation of object is effecting my FixedJoint2D anchoring point. 0 Answers

Poor performance setting Rigidbody.position many times per frame 0 Answers

How best to control rigidbody rotation within constraints 0 Answers

Rotating Camera, and Movement help. 1 Answer

On Collision my Player Spins Wildly 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