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 Oninji · Jan 10, 2012 at 05:08 PM · optimizationontriggerstaycpu

Distance Calculation vs OnTriggerStay

Greetings,

I'd like to know, which would use less CPU clock.

Briefly instantiate a Trigger sphere collision with a function OnTriggerStay.

Or

Calculate the distance between two objects and initialize the proper functions accordingly?

Thank You

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
2
Best Answer

Answer by dannyskim · Jan 10, 2012 at 05:26 PM

Basic math calculations are always going to be cheaper than using the OnTrigger or OnCollision method groups because of built in overhead when utilizing them. Assuming you cache your variables correctly in your own distance code, it should be faster, but I don't know if it will be an appreciable difference if profiled unless you're making heavy use of OnTrigger.

Comment
Add comment · Show 4 · 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 Oninji · Jan 10, 2012 at 05:38 PM 0
Share

It's to be used within the AI of an enemies, since the game is isometric I don't need height calculation and so I can easily have the wanted "Circle of Effect" by calculating distance between Enemy and Player.

It will be calculated each times the player homes-in to kill the enemy.

avatar image dannyskim · Jan 10, 2012 at 06:01 PM 0
Share

If your target is desktop platforms, you may still want to consider using OnTriggerStay. The Collider information passed from OnTrigger might prove to be useful, and it might be a welcome tradeoff compared to the $$anonymous$$or performance differences by calculating it yourself. It really all depends on what kind of AI and effects you plan to incorporate.

avatar image Oninji · Jan 10, 2012 at 06:07 PM 0
Share

There's no platfor$$anonymous$$g, it's more Hack'n'Slash. The OnTrigger would only serve to trigger a Send$$anonymous$$essage and an animation. It wouldn't do anything else. Also, the only object susceptible to trigger this should be the player.

So since it's so predictable, I would rather go for the performance route. As to insure I can run the game to the lowest performance possible.

avatar image dannyskim · Jan 10, 2012 at 06:09 PM 0
Share

By platform, i meant if for $$anonymous$$obile, Web, PC, $$anonymous$$ac, etc. I agree you should use a basic distance calculation for that use case though.

avatar image
1

Answer by arcghost · Jan 10, 2012 at 07:35 PM

A spherical trigger uses the Distance-calculation and some additional comparisons(object name, is it a trigger, and things like that).

A sphere has a radius and that is the distance from the center to the edge.

I made an example for you: So calculating the distance costs less cpu power, because there are less things to check.

alt text

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

NN setup optimization 1 Answer

How can I get the number of physical cores in the CPU (not logical cores) 1 Answer

Number of scripts per Object. Optimization question. 1 Answer

OnTriggerStay Question 0 Answers

What is the best CPU for Unity Physics? 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