Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 /
This question was closed Jul 19, 2021 at 06:00 AM by rage_co for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by rage_co · Jun 30, 2021 at 02:40 PM · 3dcolliderslayermaskcombatoverlapsphere

Replacing OverlapSphere with colliders (Detecting weapon collision with enemies - SOLVED)

So i basically have this really basic combat system that i made off Brackeys' tutorials...but now i want it to be more complex and involve colliders instead of Physics.OverlapSphere(). So i just need to ask how do i create a replacement for this single line of code

 Collider[] hitEnemies = Physics.OverlapSphere(attackpoint.position, attackradius, enemies);

but this time using colliders. just to clarify, I intend to make a combat system where the weapon has two colliders -- One on the Main Attacking part and another on other parts which will deal significantly less damage. So i have divided the mesh into two parts giving them separate colliders.

alt text

It would be great if you could just help out with the first issue though i think i can figure the multiple colliders out myself. Big Thanks in Advance.

Here is my messy combat script for reference

link text

EDIT: I managed to get a few things done that i think should've worked. I have updated my player combat script. However, things seem to be not working too well...instead of interacting with the enemies...the weapon is pushing them around. I want the weapon to phase through the enemy collider.

the scripts attached to my weapons are

This is the WeaponCollider script to manage the different collisions

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WeaponCollider : MonoBehaviour
 {
    public Collider maincollider;
    public Collider secondarycollider;
    public PlayerCombat playercombat;
 
    public bool maincollides;
    public bool secondarycollides;
 
    void Update()
    {
      if(!maincollides && !secondarycollides)
      {
        playercombat.hitEnemies.Clear();
      }
    }
 }
 

The script attached to my main collider (the one that deals more damage) is

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MainCollision : MonoBehaviour
 {
     public WeaponCollider collidermanager;
     public bool checking;
     public Collider enemytocheck;
     public bool result;
 
     void OnTriggerEnter(Collider collider)
     {
       collidermanager.maincollides = false;
       if(collider.gameObject.layer == LayerMask.GetMask("enemy"))
       {
         collidermanager.playercombat.hitEnemies.Add(collider);
       }
     }
 
     void OnTriggerStay(Collider collider)
     {
       if(checking)
       {
         if(enemytocheck == collider)
         {
           result = true;
           ReturnCheck();
         }
         else
         {
           result = false;
           ReturnCheck();
         }
       }
     }
 
     void OnTriggerExit(Collider collider)
     {
       collidermanager.maincollides = false;
     }
 
     public void CheckEnemy(Collider enemy)
     {
       checking = true;
       enemytocheck = enemy;
     }
 
     public bool ReturnCheck()
     {
       return (result);
     }
 }
 

The script attached to my secondary collider is

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SecondaryCollision : MonoBehaviour
 {
   public WeaponCollider collidermanager;
 
   void OnTriggerEnter(Collider collider)
   {
     collidermanager.secondarycollides = false;
     if(collider.gameObject.layer == LayerMask.GetMask("enemy"))
     {
       collidermanager.playercombat.hitEnemies.Add(collider);
     }
   }
 
   void OnTriggerExit(Collider collider)
   {
     collidermanager.secondarycollides = false;
   }
 }
 

The maxdamage and mindamage variables in the combat script are the damage values for the main and secondary collider respectively. Please Help!!

playercombat.txt (3.9 kB)
warhammer1.png (222.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

  • Sort: 
avatar image
2
Best Answer

Answer by xxmariofer · Jul 01, 2021 at 07:43 AM

the collider itself in the editor has a property called "is Trigger" you need to click it

Comment
Add comment · Show 13 · 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 rage_co · Jul 01, 2021 at 08:57 AM 0
Share

I ticked this property on the weapon colliders a few $$anonymous$$utes after making this edit....not the weapon can pass through enemies but it still doesn't interact.....is there a problem in my code?

avatar image xxmariofer rage_co · Jul 01, 2021 at 09:05 AM 1
Share

there could be multiple reasons why it is not working, take into account this notes:

A, At least one of the objects must be with the istrigger ticked

B, Atleast 1 object needs a rigidbody to triger events to fireç

C, make sure enemies do have the enemy layer setup

avatar image rage_co xxmariofer · Jul 01, 2021 at 10:22 AM 0
Share

No dice! I think it's a problem with my code...but i can't figure out what...plus the current code i made can process only one enemy at a time....ill try to add a list with the main collider and try...i would be grateful if you could find the anomaly

Show more comments
Show more comments

Follow this Question

Answers Answers and Comments

155 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

Related Questions

Wheel Colliders not colliding with Mesh Collider 0 Answers

WebGL Build bugged Colliders 0 Answers

basically i am having collider issues and idk wat to do 1 Answer

Slenderman script problem 5 Answers

OverlapCircleAll, layerMask ( Problem) 2 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