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 /
This question was closed Oct 07, 2017 at 06:28 AM by DayzSergeant for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DayzSergeant · Oct 07, 2017 at 04:08 AM · 2dcollisioncolliderplayer

OnTriggerEnter2D not triggering

I don't know if it's this is going to be my first 2d prototype or what because I can't see what I'm doing wrong here.

The only thing I thought of that the problem could have been would be that I'm using Transform.Translate to move the player instead of using rigidbody movement functions but I really haven't found too much on rigidbody movement for the way I want the player to move so I don't know what I'm doing wrong, I know I have to have a rigidbody on the player for trigger events to get fired but I have that on my player and my collider on my item is set to trigger and has a tag assigned to it.

Here's a couple images of my project.alt text

alt text

Here's my OnTriggerEnter2D code.

 private void OnTriggerEnter2D(Collider2D other)
     {
         print(other.tag);
     }

2.png (25.2 kB)
3.png (29.9 kB)
Comment
Add comment · Show 2
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 AshwinTheGammer · Oct 07, 2017 at 04:28 AM 0
Share

So what do you want to do with trigger what is your aim? I didin`t understand u r question what you need in script.

avatar image DayzSergeant AshwinTheGammer · Oct 07, 2017 at 04:39 AM 0
Share

I just need to get the OnTriggerEnter2D function to fire the rest of the script I know how to do and I know it will work but I have not ever worked with this this function before and the way I've found on other posts and videos does not work at all. I'm just clueless on why this is not working when it most certainly should be.

2 Replies

  • Sort: 
avatar image
2

Answer by AshwinTheGammer · Oct 07, 2017 at 04:29 AM

try this void OnTriggerEnter2D(Collider2D col) { //If collided object is block if (col.GetComponent().tag == "Row") { //My script } }

Comment
Add comment · Show 6 · 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 DayzSergeant · Oct 07, 2017 at 04:35 AM 0
Share

Yeah my bad on the script, you're right on OnTriggerEnter2D ins$$anonymous$$d of OnCollisionEnter2D but still the function does not fire at all. I will keep trying to figure this out thanks for the reply though.

avatar image AshwinTheGammer DayzSergeant · Oct 07, 2017 at 05:16 AM 0
Share

It means that you have to print the name of gameObject in which the script in. Would u upload the full code tell me the system of ur game. I also want to help u. Please give me a chance.

avatar image DayzSergeant AshwinTheGammer · Oct 07, 2017 at 05:43 AM 0
Share

Yes, I understand how the OnTriggerEnter2D works but the problem is it doesn't fire at all. As for the full code that is all that I have in the player interaction script is the

private void OnTriggerEnter2D(Collider2D other) { print(other.tag); }

The system is I'm trying to have when the player walks over the item I want him to be able to do something(The to-do something I know how to do because I've done that a lot before just never with colliders but with raycasts) but my problem is that the void that should be firing when my player enters that trigger it doesn't fire at all and that's the problem that I'm trying to figure out, I'm starting to think that it's because I move the player with transform.Translate() but I've yet to find movement code for a rigidbody that will work for a top-down movement style that I'm going for($$anonymous$$ovement is sort of like Darkwood/$$anonymous$$iami Heat)

An I appreciate you trying to help me out, don't get me wrong.

Here's my movement script: (Bit messing right now sorry bout that)

 if (!isRunning)//WAL$$anonymous$$ING
         {
             if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
             {
                 if (transform.rotation.z > 0.70f || transform.rotation.z < -0.70f)
                 {
                     transform.Translate(0, -walkSpeed * Time.deltaTime, 0);
                 }
                 else
                 {
                     transform.Translate(0, walkSpeed * Time.deltaTime, 0);
                 }
                 w = true;
             }
             else
             {
                 w = false;
             }
             if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))
             {
                 if (transform.rotation.z > 0.70f || transform.rotation.z < -0.70f)
                 {
                     transform.Translate(0, walkSpeed * Time.deltaTime, 0);
                 }
                 else
                 {
                     transform.Translate(0, -walkSpeed * Time.deltaTime, 0);
                 }
                 s = true;
             }
             else
             {
                 s = false;
             }
             if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
             {
                 if (transform.rotation.z > 0.70f || transform.rotation.z < -0.70f)
                 {
                     transform.Translate(walkSpeed * Time.deltaTime, 0, 0);
                 }
                 else
                 {
                     transform.Translate(-walkSpeed * Time.deltaTime, 0, 0);
                 }
                 a = true;
             }


Show more comments
avatar image
1

Answer by DayzSergeant · Oct 07, 2017 at 06:28 AM

So, after playing around with another component in my game it turns out all I had to to was add a box collider 2d to my player along with the rigidbody 2d. Removed the previous answer that I had posted and this is for anyone who has this problem. Thanks for the help Ashwin, sorry if my question was a bit vague need to work on explaining things a bit better lol

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

Follow this Question

Answers Answers and Comments

174 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

Related Questions

How can I detect a collision point, but allow player to pass through collider. 1 Answer

Unity2D side collision detection 1 Answer

How do I get the player and the object they touch both disappear/destroyed? 1 Answer

My object is going through boundaries Problem! 1 Answer

Unity getting an object to pass through another object but still trigger collision 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