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
0
Question by Jadlar · Jul 27, 2019 at 02:32 AM · collisionraycastcharactercontrollerexplosion

[Solved] Character Controller Explosion Detection

So, i'm trying to create a system where you can find out if you are going to take damage from an explosion if you are behind cover. I plan to shoot ray-cast to 8 positions from the rockets detonation position to the players edges (character controller) and if the player is hit by the ray-cast then that clarifies that the player should take damage. However, when the position to test for is not equal to the center of the character controller (collided.bounds.center) sometimes it doesn't detect the collision. Like in the image shown all points hit the collider at the same spot but not all return that any damage was taken. At some rotations the collision works while others they don't. Currently i'm only checking for one raycast since its not working 100% of the time. Any clues why there is the rotation issue? Thanks.

 private void Explode()
 {
     Collider[] colliders = Physics.OverlapSphere(transform.position, radius, mask); 
     for (int i = 0; i < colliders.Length; i++)
     {
         if (colliders[i].gameObject.tag == "Player") //If there is a player inside the rocket sphere
         {
             int baseDamage = CoverCheck(colliders[i]);
             Debug.Log(colliders[i].gameObject.name + " took " + (baseDamage * damage) + "  damage");
         }
     }
     Destroy(this.gameObject,3);
 }

 private void OnDrawGizmos() //Draw the area of potential rocket damage
 {
     Gizmos.color = Color.red;
     Gizmos.DrawWireSphere(transform.position, radius);
 }

  private int CoverCheck(Collider collider) //See how much of the character is covered if any
 {
     
     Vector3 v3Pos = transform.position;
     Bounds bounds = collider.bounds; 
     int notBlocked = 0;
     Vector3 v3Corner = Vector3.zero;
     Vector3 v3Center = bounds.center;
     RaycastHit hit;

     //Sets a new raycast destination to check for
     v3Corner.Set(v3Center.x, v3Center.y + 1.5f, v3Center.z + 0.6f);

     Debug.DrawLine(v3Pos, v3Corner, Color.green, 20.0f);
     if (Physics.Linecast(v3Pos, v3Corner, out hit) && hit.collider.name == "Player")
     {
         notBlocked++;
     }
  
     return notBlocked;     
 }
screenshot-7.png (177.3 kB)
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 Jadlar · Aug 01, 2019 at 03:33 AM

Solution: the CharacterController has some kind of issues with Raycast I have not looked into the reasons exactly why, but that is the fundamental issue. In my case since I still need my CharacterController all I did is add a capsule collider slightly above the CharacetrController collider. With this all Raycast can be detected along the outside of the collider which is what i'm looking for.

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

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

Related Questions

Detect RaycastHit on Character Controller 2 Answers

How can i detect the normal of the collider the Character Controller is touching. 2 Answers

Help Understanding Raycast 2 Answers

How do I make a Character Controller NOT collide with Rigidbodies? 3 Answers

GameObjects glitching through other Objects when being held 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