Great thanks so much for that, as well I had a quick question about “when item collides with” block in this scene https://cospac.es/dyA1 only one of those works, code is Coblocks(3). When the player walks over trigger0 nothing happens but trigger1 works?
unfortunately I couldn’t find your
when item collides - blocks in your shared scene. But I believe I know where the problem lies:
Keep in mind that you can not place multiple event handlers of the same type on one item. This means if you add two
when item collides on the same item, only the last event will be triggered. Let’s demonstrate with an example:
We add two events of the same type on an item like this:
This is what happens:
The latest event-handler always overwrites all others of the same type on an item.
The different types of event handlers are:
-When item collides
-When item is clicked
-When item is hovered
Hope that makes using event handlers more clear to you!
I see thanks, so let’s say if i wanted the camera to trigger let’s say 6 seperate events, each event activated when you walk over something, i need to create six different events and placecthrm in separate windows?
here’s an example on how you can set up collision events for one item against many different ones.
In the scene: a Boy-item walks forward into 5 different cubes.
We create the
when item collides with [anotherItem] - block. This block will trigger whenever the boy collides with any other item in the scene.
When you drag this block into the workspace it creates a variable called "anotherItem". This variable can be found in the Data -> Variables category and represents the latest item the boy has collided against.
To create different behaviour for any of the other cubes, we use if-statements to check what kind of cube has been collided against like this:
Here we create if-statements to check which cube was collided, then let the boy say something different depending on the cubes.
With this script in place, let’s move our item forward and see what happens! Make sure that event-handlers are created before you animate items, otherwise the handlers are set after the item is done moving.
We add event handlers on the cubes instead, not the boy. This way we make sure that only one collision handler is on any given item.
Solution a) is more elegant as you can manage collisions from one event-handler. Solution b) is more suitable for quick collision testing between a few single items.
Awesome, this has helped tons on getting me past this hurdle
Thanks a lot. Your example was of great help.
However, I wasn’t able to generate the “anotheritem” variable myself. I did as you said and pulled it into the workspace but I only get in German “keine Variablen” which means “no variables”.
I wanted to try the following thing: A shooting star is fired. If the star hits the correct brick it vanishes. If it hits the wrong brick, nothing happens (except a taunting comment).
For that I tried your code and copied it. However, I cannot re-create it with the given block code. Here is an example what I mean:
The active code is the code I copied from you. The greyed out, inactive, code is mine. I have no means to re-create the yellow block #2 (your picture above) with the collides with item [anotheritem]. I have to add a red variable…and then it doesn’t work.!