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 /
avatar image
1
Question by ungalyant2 · Sep 27, 2011 at 12:55 PM · raycasthitcastaoecapsulecastall

CapsuleCastAll not returning hits

Hey guys, I'm currently working on trying to implement some abilities for characters, the ability I'm working on at the moment is meant to teleport the player forward and deal damage to all the enemies lying between where the player started and where they finished, with a certain with, so I'm using a CapsuleCastAll with a layer mask specifically for enemies and then merely calling a deal damage function for all the enemies returned, only for some reason it doesn't seem to be hitting enemies that are CLEARLY well within the cast, and sometimes it returns none at all. I tried making the radius huge and it changes nothing.

                 p1 = myTransform.position + controller.center + Vector3.up * -controller.height * 0.5F;
                 p2 = p1 + Vector3.up * controller.height;
                 layerMask = 1 << 12;
                 abilityTars = Physics.CapsuleCastAll(p1, p2, controller.radius * 5f, myTransform.TransformDirection(Vector3.forward), range);
                 p3 = p2 + myTransform.TransformDirection(Vector3.forward) * range;
                 Debug.Log("enemies hit = " + abilityTars.Length);

                 if (range < 1.5)

                 {
                     Debug.Log("dashing into wall");
                     movement = myTransform.TransformDirection(Vector3.forward) * (range - 0.3f);
                 }
                 else
                 {
                     movement = myTransform.TransformDirection(Vector3.forward) * range;
                 }

                 controller.transform.position += movement;
                 int enemiesHit = 0;
                 foreach (RaycastHit hit in abilityTars)
                 {
                     if (hit.collider.gameObject.tag == "Enemy")
                     {
                         enemiesHit++;
                         GameObject Enemy = hit.transform.gameObject;
                         EnemyDamage enemy = Enemy.GetComponent<EnemyDamage>();
                         if (enemy == null)
                             continue;
                         enemy.SendMessage("ApplyDamage", 2);
                         stats.WriteText(Enemy.transform.position, 2, null, Color.white);

                     }
                 }

any ideas on what may be happening?

Comment
Add comment · Show 1
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 rah · Feb 18, 2013 at 05:27 PM 0
Share

I have a similar issue: http://answers.unity3d.com/questions/401554/capsulecastall-fails-after-20-calls.html#comment-401565

I don't know what's going on here, but I can demonstrate that the first 20 CapsuleCastAll() calls seem to work right, and all calls after that point return nothing. I don't have any idea why though. It's like there's some pool of stored collisions I have to clear out or something.

2 Replies

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

Answer by Bunny83 · Apr 11, 2013 at 03:23 PM

A CapsuleCast has the same limitations as a Raycast. That means if it starts inside the object, it can't hit the object. Making the radius huge will just skip more objects which are within the initial position's sphere.

The best way for area effects is Physics.OverlapSphere. It only tests against the colliders bounding box and not the true collider, but it's very fast and reliable.

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
0

Answer by syclamoth · Sep 27, 2011 at 01:12 PM

What you are looking for here is Rigidbody.SweepTestAll- it does almost exactly what you want here! You can use it for any kind of collider, provided that it is controlled by a rigidbody (it can be kinematic if you don't need physics).

Comment
Add comment · Show 9 · 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 ungalyant2 · Sep 27, 2011 at 01:16 PM 0
Share

I had many many complications with rigidbodies, so the enemies are actually currently using character controllers, is there a sweep for that? Or do I really need to change them to rigidbodies?

avatar image syclamoth · Sep 27, 2011 at 01:26 PM 0
Share

CharacterControllers are usually more trouble than they're worth, in my experience. The simple functionality which they make easier is by far countered by the sheer number of things they make more difficult!

avatar image ungalyant2 · Sep 27, 2011 at 03:17 PM 0
Share

well for me, despite manipulating the velocity of the rigidbodies directly, they were still getting affected by drag and mass, which seems retarded, and they were just jittering about a lot, and dissapearing and reappearing and flipping around, it was very infuriating, so there's no way to sweep character controllers?

avatar image syclamoth · Sep 28, 2011 at 01:19 PM 0
Share

If you set your rigidbody to rigidbody.is$$anonymous$$inematic = true, then you won't have to worry about all that jittering, and you can move it just with the transform.

avatar image ungalyant2 · Sep 29, 2011 at 01:58 AM 0
Share

Ok, I've decided to take your advice and swap them back to rigidbodies, but bearing in $$anonymous$$d that they're now kinematic, they obviously don't collide with eachother, the floor and walls and use gravity, what can/should I be doing to do this then? And will this be processor intensive over just using the physics engine?

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why are RaycastHit surface normals of corners not interpolated or otherwise correct? 1 Answer

How to get information from raycast? 2 Answers

How to get a Vector3 from a RaycastHit variable? 1 Answer

Physics Casting Performance 1 Answer

on raycast hit assign game object? 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