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 /
  • Help Room /
avatar image
0
Question by steviebob · Jun 12, 2016 at 05:26 PM · scripting problemvector3gameobjectsdistance checkboundingbox

Get All Game Objects Between 2 Points

Hi, I'm getting started making a farming/harvesting type game and I'm trying to figure out how to harvest something without actually hitting it directly.

So far, I've got it so that if you click on the thing to harvest (A simple cube at the moment), if you're within a reasonable range of it, I can act on it.

However, what I'd like to do is when I hold the mouse button down, the longer I hold it, the further the hit becomes in a straight line. i.e. less than 1 second is a click, so least powerful and must be immediately adjacent to it. However for 2 seconds for example, I'd like to harvest in a line from where I'm facing, x distance in front of me.

I'm fine with the bit about guaging how long the button has been held down, as well as how to identify a point x distance in front of the character. The bit I'm stuck on is what is a sensible way to "harvest" everything in a line if I'm not directly clicking on it?

I was thinking "get me all game objects between these 2 points and I'll harvest the ones which are "plant" objects (ignoring things like random, non harvest-able game objects)", but I'm not sure how to do that.

Also, this method has the problem that if the harvest-able plants are in front of the character, but doesn't quite intersect the line between the 2 vectors? I guess it would be better to draw a box in front of the character, but still not something I'm sure how to do.

Any suggestions?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by steviebob · Jun 12, 2016 at 05:48 PM

I've just found the answer. It looks like Physics.RaycastAll is exactly what I need.

In order to get around the issue of "what if the ray jut misses it", I guess I'll just cast several at various heights and points to be sure, then filter out the duplicates.

I assume this is a reasonably efficient approach? (Should have been a comment but my reputation isn't yet high enough).

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

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

Related Questions

Check if 2 or more objects of same type is near object. 1 Answer

My collectable objects don't respond like they should after calling a coroutine for the first time? 0 Answers

creating 3d melee cone splash attack 1 Answer

InverseLerp for vector3 1 Answer

Searching a function to get the rotation of one Vector3 in relation to another 1 Answer


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