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