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 MiloRoban · Apr 20, 2017 at 09:01 AM · c#javascriptscripting problemcollision detectionontriggerenter

Having difficulties making a block be a death trigger for a ball.

I am working on a pretty simplistic game right now, and this is really impeding my ability to finish this project. I am trying to get a block to be a trigger so when the ball hits the block, the ball get's destroyed and respawns. I have tried probably every tutorial on YouTube, no scripts worked. Can you make a tag that you can put on an item that makes it a death trigger?

If you need more information, I will provide it.

Thank you.

Comment
Add comment · Show 3
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 BaldBeardedMonk · Apr 20, 2017 at 09:29 AM 1
Share

please post your code.

avatar image MiloRoban BaldBeardedMonk · Apr 22, 2017 at 12:57 AM 0
Share
   void OnTriggerEnter(Collider col){
          Destroy(col.gameObject);
          }
      
      void OnTriggerEnter(){
      Destroy(gameObject);
      }
avatar image BaldBeardedMonk MiloRoban · Apr 22, 2017 at 03:00 AM 0
Share

Hello,

Have you marked the Collider component of the ball as "is Trigger" in the inspector ? If you want the ball to be a collider and not Trigger then you should change the code to

 void OnCollisionEnter(Collision col)

Also there is no need to use two OnTriggerEnter functions. Just use

 void OnTriggerEnter(Collider col)
 {
  Destroy (col.gameObject);
 }

If the ball is marked as trigger use OnTrigger else use OnCollision. Also you have not checked if the gameobject colliding is a ball or not. the above code will destroy any gameobject co$$anonymous$$g in contact with the block. Hope this helps :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sadowlight123 · Apr 25, 2017 at 05:11 AM

hello there,

you need to do the following: 1- this code should be on the death box if it is not

  void OnTriggerEnter(Collider col){
           Destroy(col.gameObject);
           }

2-add a collider to both the death box and the player (if they dont have it already) 3-tick the trigger box that is on the death box

additional : add a tag to the player and call it "Player" then change the code to be like :

 void OnTriggerEnter(Collider col){
 if(col.tag=="Player")
           Destroy(col.gameObject);
           }

Hope it helps

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 KrisDevelopment · Apr 25, 2017 at 04:51 PM

@MiloRoban Here's the 4 things that need to be in place in order for your code to work: 1: have your code (as in the examples above) on the death trigger :

 void OnTriggerEnter(Collider col){
                Destroy(col.gameObject);
     }

2: Add a collider to the death trigger and check the check box for trigger. Also add a collider to your ball.

3: The one thing that everyone else missed is that YOU NEED TO HAVE Rigidbody component on your ball object. Without one it wouldn't work.

Bonus: Make sure their layers are seeing eachother in the Edit>Project Settings>Physics.

Good luck!

Comment
Add comment · Show 1 · 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 sadowlight123 · Apr 25, 2017 at 09:08 PM 0
Share

as $$anonymous$$risDevelopment said , we did forget to tell you to add a rigidbody on at least one of the two colliders , in our case the player ball , but since your ball already moves I assume you already have it on .

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

On trigger turn off particles and lights make room dark,On trigger by FPC disable/destroy lights and particles 0 Answers

How to detect when two colliding objects create a corner? 1 Answer

Help change the subject of this Script 1 Answer

Grab/Throw Mechanic.,Grab/Throw Objects Mechanic 0 Answers

[SOLVED]Problem with 2D Collider 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