About 'Colliders, Collision & Triggers'!

In this video (objectives)…

  1. Stop our ball rotating by freezing Z axis rotation on our Rigidbody.
  2. Create a lose collider.
  3. Discuss difference between trigger and collider and examine the event matrix for collision events.
  4. Load Game Over screen when ball passes through lose collider.

After watching (learning outcomes)… Make the game load a new scene when an object passes through a trigger volume.

(Unique Video Reference: 7_BR_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Well, I have a bug and I can’t figure out what’s going on.

After a few seconds, even if I just start the game and do nothing, the collider is activated and the next scene is called.

The time for this isn’t fixed, can vary from 3 to 30 seconds. The “ball” (Baby) remains in the “paddle” (Troller).

If you are talking about there are some line endings are mac or windows error.
just save your script as
save as
then choose in the save box save with encoding windows format . (sorry you are using mac so save it as mac format)
then save it.

@DK_Z I don’t think the error with the collider has anything to do with the endlines, but for sure is an annoying problem.
I’ll try your solution to fix it. Thank you.

I hope @Rick_Davidson has some time to take a look at the collider problem and put some light on this.

Hey @FernandoLuizRosa

do you know which gameobject triggers the lose collider?

If it’s the baby then try setting the collision detection to ‘continuous’ for the baby’s RigidBody2D component (it solved some weird collision behaviours for me where the ball sometimes glitched inside the paddle)
collision_detection_mode


You could also set the rigidbody's type to kinematic while it is stuck to the paddle. The kinematic mode makes the rigidbody ignore all applied external forces (like gravity).
Just add

GetComponent<RigidBody2D>().isKinematic = true;

to your LockBabyToTroller method (or to the Start method because you have to do that just once) and a

GetComponent<RigidBody2D>().isKinematic = false;

to your LaunchOnMouseClick method (you know where exactly ^^).


Hope this helps

Thank you @Banpa, looks like your first suggestion solved the problem (Collision Detection: Continuous)

Hi,

First of all thanks for a fantastic course, I’m really enjoying it!

In the tiny collision detection script, the parameter “collision” that is declared in () after OnTriggerEnter2D, is greyed out and unknown. So far I’ve been pretty much following step by step, so I’m not sure if and where I missed something. (Probably :slight_smile:)

If anyone knows what’s the issue, I’d be super happy. Thanks for the help!

No issue, its just saying that we have information about the specific collision event (ie. who bumped into me) and we aren’t using that extra information for anything. We don’t need to use it for what we are doing, so its okay to not take advantage of it. You can check this by removing Collider2D collision (ie. just leave the parentheses after OnTriggerEnter2D empty) and it should still work.

Thank you Rick!

Since everything else seems in place, I assumed that this message is connected:

15

I haven’t been able to trigger the Game Over scene. The ball falls through (as it should) and that is it.

Hi,

Your class is called Collision but your filename is saved as LoseCollider, these need to be the same for Untiy to use them correctly. I would suggest renaming your class to LoseCollider.

Then make sure that the script is still attached, run the game again and you should find the code in the OnTriggerEnter2D method is executed correctly.

Hope this helps :slight_smile:

Thank you Rob, it helped. Of course it was a tiny thing and somewhere else than I thought. You’re a life saver :slight_smile:

1 Like

You’re very welcome, happy to help and glad you can move forward again :slight_smile:

Hey Everyone,

The issue I am having:
The ball is pushing my princess sprite.

What I want to occur:
I want my princess’ collider to ignore contact with the ball.

What is actually occurring:
The first contact the ball makes with the Princess is triggering the collider then subsequent contacts are passing through without triggering the collider.

Here is a clip of the gameplay:

it is hard to see the ball passes through the princess again but it does without knocking her again.

Here is my Princess Script

Hi,

Have you considered using the Layer Collision Matrix? As you are already using layers, it may make this fairly straight forward for you.

Incidentally, your can just copy/paste your code into the forum and apply code formatting, it makes it a lot easier to read and for others to subsequently copy/paste back chunks of it when they try to help :slight_smile:


See also;

Hey @Rob

I have not. To be honest I didn’t know it was a thing. I will look into that today to see if I can self correct the problem and let you know how it went.

Thanks for the pointer on the code as well. I thought the screenshot looked neater but being able to copy/paste code is def more viable for code correction.

1 Like

No worries. It was, from memory, covered in the original Laser Defender project I think. Used to prevent enemy projectiles destroying enemies and player projectiles destroying the player - sounds like a similar situation for you.

Hello, i have little problem right here. LoseCollider works for me and it does change the scene, but during the coding i cannot use this shortcut, which shows me examples like here, in the video:

And i cant see this little menu

Can somebody explain what am i doing wrong? The code works at all, i am just wondering why it doesnt work for me in visual studio(just this example, everything before work like in video)

I seem to be having something off with the Lose Collider I keep making and setting it as instructed the script to which I was happy i got correct during the challenge I recopied letter to letter to make sure but no matter what it won’t head on to the Game Over Scene I’m a bit confused whats i’ve done wrong will review video again to see

Here is a look at the set up

Well I have No idea what I did XD I just kept messing with the script changing the names of the scenes and I guess that did it but now it works XD

Just a small bit of feedback on this lesson. Your slide displaying the collision/trigger matrix is not very color-blind friendly. The yellow and green font look nearly identical to me.

Cheers!

1 Like

Privacy & Terms