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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by thelebaron · Apr 14, 2014 at 02:07 AM · distancemeleeradiusphysics.overlapsphere

Overlap sphere radius problems

I have a little melee function in the code below. The problem is that for some reason the radius of the overlap sphere doesnt seem to work properly, a radius of 1 seems to encompass an area far far greater(more like 10). Secondly nothing actually happens if the object you are trying to melee is at point blank range.

With the dist < Range the issue of limiting your own melee range seems to be fixed but that hardly seems ideal, otherwise whats the point of the radius? And the issue of a point blank attack is still a problem.

Using Gizmos.DrawWireSphere the overlapsphere appears like it should be in the correct place, just I have no idea why it doesnt function as I thought it should

         var colliders = Physics.OverlapSphere (transform.position, 1f);
         foreach (var hit in colliders) 
         {
             Vector3 dir = (hit.transform.position - transform.position).normalized;
             var direction = Vector3.Dot (dir, transform.forward);
             if (direction < MeleeDirection)
             {
                 continue;
             }
             float dist = Vector3.Distance(hit.transform.position, transform.position);
 
 
             if (hit.rigidbody && dist < Range) 
             {
                 HealthManager targetHealth = hit.transform.GetComponent<HealthManager>();
                 if (targetHealth)
                 {
                     targetHealth.TakeDamage (damage, tr.forward);
                     hit.rigidbody.AddForce (300, 300, 300);
                     TNManager.Create(gibsPrefab, hit.transform.position, hit.transform.rotation);
                 }
             }
         }
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
Best Answer

Answer by getyour411 · Apr 14, 2014 at 02:28 AM

Do your enemy units have a large sphere or other collider, like maybe an awareness collider or something like that, which might be within the OverlapSphere? OverlapSphere is used frequently so I have to assume any issues you are experiencing are unique to your setup.

Also, what's this for?

  if (direction < MeleeDirection)
 {
 continue;
 }

In your 'point blank' issue, using debug, what is the value of direction and MeleeDirection?

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 thelebaron · Apr 14, 2014 at 06:08 AM 0
Share

Ahh the enemy units do have an awareness collider(a big old sphere collider) on em in addition to their capsule collider I completely forgot about! I also sorted the point blank issue by making the other colliders slightly larger, seems to work now so I guess I can consider that part fixed as well, thought Im not sure why that sorts it out.

The part you mentioned is just for a fov type of effect, ignore colliders outside of a value so the overlap melee sphere acts as a sort of melee cone.

Thanks! I dont know how to mark this as resolved(is there a way to do that?).

avatar image getyour411 · Apr 14, 2014 at 07:33 AM 0
Share

Glad that's sorted out, I change comment to Answer.

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

21 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

Related Questions

Check Radius Problem 2 Answers

Melee for 2.5D Platformer? (C#) 0 Answers

How to apply explosion/magic/grenade damage to detect objects (enemies) within a given radius, and apply AOE damage to each enemy based on its distance? 2 Answers

How to make this script find distance inside radius? 1 Answer

Math Question: Get EnemyObject to NavMeshDestination x Units from Player 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