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
2
Question by Andrea · Sep 29, 2011 at 04:18 PM · rotationrigidbodycolliderstriggersstatic

Can i Move/Rotate triggers without Rigidbodies? And other collider questions.

Hello, i've been reading that moving static colliders (without rigidbody) it's bad... but what about triggers? In my game i have many pickable items, and these items use sphere triggers. To make these items look nicer i rotate them every frame and so, at the same time, i am rotating the triggers too. Is this a problem for performance? Or because the triggers are ignored by the physic engine it's fine?

About the colliders. In my game for walls, fornitures and floor i use many static colliders. For performance reasons i would like to know if the engine calculate all the collider at the same time or just the ones that are visible by the camera. And i would like to know too if there is a performance loss if these static colliders intersect with each other.

I am developing for iOS/Mobile.

Thank you and sorry for my english :)

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

3 Replies

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

Answer by testure · Sep 29, 2011 at 04:21 PM

Triggers are colliders, so yes- if you're going to move them put a kinematic rigidbody on them. They are still treated as physics objects whether they're triggers or not.

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
3

Answer by Andrea · Sep 29, 2011 at 07:05 PM

I downloaded Unity Pro (trial) so that i could test things myself using the profiler and that it's what i have discovered:

With 200 rotating items with sphere triggers on the screen:

1) Between having or not the Kinematic Rigidbody the performance difference on the physics side wasn't very noticeable. But with 200 kinematic rigidbody components on my items i had a great overhead on the scripts side.

2) The best solution, that gave me a dramatic performance boost was (obviously) to create an empty gameobject, put in it the sphere trigger and the pickable item script and then parent the mesh with the rotating script to it. Doing so the item could continue rotating but the trigger sphere didin't move.

I hope my info can be useful.

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 aldonaletto · Sep 29, 2011 at 07:41 PM 0
Share

I'll check this alternative later. Thanks for the hint.

avatar image
0

Answer by aldonaletto · Sep 29, 2011 at 06:03 PM

I have the same problem: about 200 pickable items with spherical triggers and rotating all over my level. I created a static boolean variable to enable or disable the rotation for all of them at once, and tested the difference. From the physics engine point of view, the extra time is zero or totally negligible. The rendering time, on the other hand, seems to be about 10% bigger when the items are rotating! (doesn't make too much sense, for sure).
At the end, I adopted a simple cycle saver measure: if the distance from the player is above some limit (500 units, in my case), I simply disabled the renderer and stopped the rotation. This made a reasonable difference - in the worst case, the frame rate was 17 with infinite distance and 23 with a 500m limit.
I implemented this using a static Transform variable with the player transform, and in the rotating items I included a simple distance comparison.
This was added to the Control.js script (attached to the player):

static var trPlayer: Transform; static var limitDist: float = 500;

function Start(){ trPlayer = transform; } And this was included in the rotating items script:

function Update(){
    var dist = (Control.trPlayer.position - transform.position).magnitude;
    if (dist > Control.limitDist){
        renderer.enabled = false;
    } else {
        renderer.enabled = true;
        transform.Rotate(0, 360 * Time.deltaTime, 0);
    }
}
Comment
Add comment · Show 3 · 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 Andrea · Sep 29, 2011 at 06:54 PM 0
Share

Hi, to avoid having item rotating around the level when not needed, i just used the OnBecameVisible and OnBecameInvisible functions to disable the ItemRotator script when not visible by the camera. I think it's faster and cleaner :)

avatar image aldonaletto · Sep 29, 2011 at 07:35 PM 0
Share

It's cleaner, but not necessarily faster: be aware that visible and invisible in this case mean inside and outside the view frustum. If your map is square, when the player is at any corner and looking to the center, almost all objects will be considered visible!
Since you're developing for mobile devices, some compromises may help making this more effective: use the far clipping plane at the shortest distance possible, so objects beyond it will not rotate (due to your code) nor be rendered (only objects inside the frustum are drawn).

avatar image Andrea · Sep 29, 2011 at 09:28 PM 0
Share

Yes, i know that visibility is triggered by the frustum. $$anonymous$$y game is 2D so in my case this it's not a problem. You can try using a big sphere trigger on your main character that activate all the item that get touched or maybe divide your level with big sphere triggers that activate the item close to them when the player touch them. Trigger are very fast and super optimized and you can avoid to check the distance in 200+ objects at the same time.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating a transform with child rigidbodies 0 Answers

Having problems with playing a sound (C#) 2 Answers

Collisions While Rotating Objects Without Character Controllers 1 Answer

Is there a way to add different trigger to each specific game Object 0 Answers

Rigidbody.isKinematic vs. moving a static collider via script 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