Delivery Driver

I am starting the Complete C# Unity Game Developer 2D tutorial. In the Using OnTriggerEnter2D() lesson I have an issue. The script for OnTriggerEnter works when I pass through one object, but OnCollisionEnter doesn’t trigger on the other object as I saw in the video. I am able to pass through an object, but not push the other like I was before. Here is my code. Let me know if you need any more info, thanks.

Hi,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

In your screenshot, I can see a little asterisk in the Collision.cs tab. This means that the script has not been saved yet. Try to save it. Maybe that’ll solve your problem.

Hope this helps. :slight_smile:


See also:

Ok, thanks for the info. The saving did not resolve the issue.

Could you please share more information on your game? I read that “OnCollisionEnter doesn’t trigger on the other object”. What is “the other object”? Would you mind sharing screenshots of what you have in your scene and in the Inspector of the relevant game objects?

The object is a circle. I’m not able to “bulldoze” or push the circle as I’d like, so with the rectangle, I just want to pass through (which it does) and push the circle instead.


Do both game objects have got a non-trigger Collider2D component attached? To be able to push a game object, the other game object needs a Collider2D component and a Rigidbody2D component.

Exactly as @Nina said you need to have on your “Car” object and on the other one RigidBody2D to be able push it on the screen.

Yes. Hopefully these screenshots might indicate where my issue is though.


Yeah, it’s like @Nina said; you need a non-trigger Collider2D on your player. You don’t have one

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms