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
0
Question by joyouletto · Jun 11, 2014 at 10:42 AM · performanceprogramming

Best way to handle high number of usable/pickable objects?

Hey,

I'm trying to learn how the optimal game logic should work and what are the best ways to create game mechanics in terms of performance.

I want to have a lot of pick-able objects, usable objects, containers, and "usable" characters.

Character should be able to "activate" or use them only if he is near them.

What is the best way to achieve this without making it too heavy for performance?

The simplest way that comes to my mind is to calculate distance between the character and every object every frame/time but this will be probably not optimal when there will be few hundreds of them in one scene.

Do you have any ideas how this should be build? What about the performance? How other games handle this?

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 Nick4 · Jun 11, 2014 at 11:10 AM 0
Share

Do you want usable items to be picked automatically or only upon user's input?

avatar image joyouletto · Jun 11, 2014 at 02:56 PM 0
Share

@Nick4

I want player to be able to use/pick/activate an item only when the character is in front of it and the item is near the center of a screen and the distance is less than about 2 meters.

1 Reply

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

Answer by HarshadK · Jun 11, 2014 at 11:13 AM

For:

Character should be able to "activate" or use them only if he is near them.

use trigger collider to these game objects and when the character collides with trigger perform the action that you want character to perform like picking it up or whatever.

For informaiton about triggers to start with:

1) Colliders as Triggers

2) Collider.OnTriggerEnter(Collider)

Also since we are at high number of objects one more thing to know is that don't just instantiate and destroy game objects rather use pooling for these game objects for efficient performance.

Comment
Add comment · Show 5 · 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 joyouletto · Jun 11, 2014 at 02:44 PM 0
Share

Thanks.

I was thinking about using colliders and triggers too.

The thing is I need the character to be able to activate an object only if the object is on the center of the screen and when the distance is less than about 2 meters.. What will be a better option to achieve this. By using a additional collider in front of the camera? Or maybe with a raycast from center of the screen ins$$anonymous$$d of a collider?

avatar image HarshadK · Jun 11, 2014 at 04:38 PM 0
Share

Distance between which two objects? Player and pickup object or camera and pickup object?

avatar image joyouletto · Jun 11, 2014 at 11:08 PM 0
Share

@Harshad$$anonymous$$ First Person Camera so generally same distance from player's "head" and the main camera.

I'm thinking about raycast because it always points into one "pixel" (afaik), so when there are two or more different objects near each other, the first hit is stored and it's clear which of them (objects) is in the center of the screen and which of them is hit first.

With colliders and triggers it is possible that two different objects will collide with the "character collider" that is placed for example in the front of the character. Anyway I know that I can send an event on the collider enter so just the first object that collides will be stored.

In short words. Raycast always hits only one object and it's clear which one. Collider can collide with multuiple objects at once beacause it's a three-dimensional thing in the space.

Am I thinking right?

Which option is better in your opinion? Or maybe there is some other, better approach?

avatar image HarshadK · Jun 12, 2014 at 05:05 AM 0
Share

In this case a raycast would be better since you only need to do it once when the player enters the trigger of pickup object. If you use collider then it will generate unnecessary OnTriggerEnter calls. Also because this is an FPS you can raycast from the position of camera since position of camera will be the center of screen and also you don't have to perform any calculations to get the center of the screen itself.

avatar image joyouletto · Jun 25, 2014 at 08:46 AM 0
Share

@Harshad$$anonymous$$

Thanks for your help! I will try with a raycast.

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Is variable framerate acceptable? 1 Answer

Why is ECS better than actual Unity Entity-Component pattern ? 1 Answer

Should I read variables serveral times, or store as temporary variable? 1 Answer

Reference all objects inside of an Array or List? 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