Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Akorna · May 10, 2014 at 05:43 PM · tilemappathfindingspherecastspherecastall

How to use correctly a SphereCastAll

I'm trying to create a tactical-turn-based-tile-game. I need to be able to check all the available points to where my character can move in a radius of 2 for exemple. I was thinking about using SphereCastAll to get all points around the unit doing the following:

RaycastHit[]FoundWaypoints = Physics.SphereCastAll(Character.transform.position, 2.0f, Vector3.forward);

But this doesn't quite do what I expect it to do so I think I'm getting all wrong how SphereCast is used. What I except that is happening is a sphere that gets build around Character position in a radius of 2, but that's not really what is happening. Does anyone have an idea what I could do to make this work?

Sorry if it isn't so clear I'm not that good in english. Tell me if something isn't clear.

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

Answer by Deign · May 10, 2014 at 05:51 PM

Spherecast is used the same as Raycast, the only difference is the diameter of the raycast. What I think you're actually trying to do is OverlapSphere

https://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html

Comment
Add comment · Show 2 · 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 Akorna · May 10, 2014 at 06:00 PM 0
Share

This was exactly what I needed cheers. Just going to try and figure out now how I could cut the corners.... that's gonna be a bit harder ... ^^

avatar image sudhir_kotila · Oct 30, 2015 at 11:43 AM -1
Share

Thank you so much. Physics.OverlapSphere is very much useful for me to detect multiple object within specific radius. Thanks a lot.

avatar image
0

Answer by ttRevan · Oct 30, 2015 at 08:51 PM

IMHO you don't need Physics at all. Simple tiling cordiates can solve your problem:

 ------ ----- ----- -----
 | 1.1 | 1.2 | 1.3 | 1.4 |
  ----- ----- ----- -----
 | 2.1 | 2.2 | x   | 2.4 |
  ----- ----- ----- -----
 | 3.1 | 3.2 | 3.3 | 3.4 |
  ----- ----- ----- ----- 

You can then find matching tiles:

 var xNum = Mathf.Ceil(range / tileSizeX);
 var yNum = Mathf.Ceil(range / tileSizeY);
 
 List<Tile> availPoints = new List<Tile>();
 for (var i = 1; i <= xNum; i++) {
     availPoints.Add(allTiles.Get(playerTile.x + i, playerTile.y));
     availPoints.Add(allTiles.Get(playerTile.x - i, playerTile.y));
 }
 for (var i = 1; i <= yNum; i++) {
     availPoints.Add(allTiles.Get(playerTile.x, playerTile.y + i));
     availPoints.Add(allTiles.Get(playerTile.x, playerTile.y - i));
 }
 

In case you have hex tiles, algorithm will be somewhat different, but idea is the same.

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

23 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

Related Questions

How to reach 2D Grid from script? How to reach every tilemap location and use them for pathfinding? 1 Answer

TBS - Suggestion (Beginner) 0 Answers

trying to do pathfinding for my guard in 2d grid 0 Answers

Trying to find whether a point is close to the edge of a surface 2 Answers

How can i take the right path in this pathfind algorithm? 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