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 naveenrai8 · Mar 23, 2013 at 05:06 AM · movementdirectionspherecastall

how to find Object anywhere in the radius of say 10 units

Hi All, I am very new to unity and trying to build a game. A Scenario in my game is following: 1. Object will start moving in right direction (vector3.right) 2. while moving, it will continue search for any object in the radius of say 10 units. (means a kind of sphere that continue to search in all directions) 3. as soon as collision happens with say object2, object have to move from its current position and direction to object2's direction.

I search and found physics.shperecastall may be the starting point. But, i could not find out how to get the direction of moving object and object with which it colloid.

Any help would really be great!! Please point me what and where to start. Many thanks in advance!!

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 robertbu · Mar 23, 2013 at 07:01 AM 1
Share

For detecting other game objects, see Physics.OverlapSphere(). As for moving towards another object, I'd need to understand if you are trying to use Physics (i.e. Rigidbody and Addforce) to move your objects, translating using the Transform, or are you using a character controller.

avatar image naveenrai8 · Mar 23, 2013 at 07:19 AM 0
Share

Hi Robertbu, Thanks for your reply! What is the difference between Physics.OverlapSphere() vs Physics.SphereCastAll()???

"As for moving towards another object, I'd need to understand if you are trying to use Physics (i.e. Rigidbody and Addforce) to move your objects, translating using the Transform, or are you using a character controller." I am not using any physics to move object, ins$$anonymous$$d have written script that simply use translate and position api to move object.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FWCorey · Mar 23, 2013 at 09:53 PM

After using a Physics.OverlapSphere to get an array of colliders in range you can use "collider.transform.forward" to get it's heading.

See - Transform-forward and - Physics.OverlapSphere for example code.

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
1

Answer by robertbu · Mar 23, 2013 at 10:09 PM

OverlapShpere() finds any objects without a sphere of a particular position. SphereCastAll() is like like a Raycast in that it takes a sphere and "pushes" it through the scene from a specified starting point in a specified direction looking for hits. OvelapSphere() gives back a array of colliders (hitColliders is used below). Once you find the one you want to use you can do something like:

 transform.LookAt(hitColliders[i].transform);
 transform.translate(transform.forward * speed * Time.deltaTime);

Or you can so something like:

 transform.position = Vector3.Lerp(transform.position, hitColliders[i].transform.position, speed * Time.deltaTime);
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

12 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

Related Questions

Transform position of an object at particular angle/direction 3 Answers

Custom movement script problems 1 Answer

Camera relative movement 0 Answers

Get which way the player is moving from character controller.move 2 Answers

Rotation and movement? 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