|
||
Hey all, I'm going to show you how to make a park were a light gets turned on using a script. To start off we're going to add the objects required to make the park. Let's start with a box, make its position 0, 0, 0 and its size something like 1, 0.1, 1. The size isn't really important so you can make it as big as you want. It's also important to turn physics on the box, and can be done be checking physics enabled to be on. This can be found in the Behaviour menu of the boxes properties. Now let's put some lights into the scene, we're going to need a directional and a point light for this tutorial. Position the directional light at 0, -5, 0 and adjust its diffuse value to #494949
Now make a sphere, enable its physics and make it movable remembering to give it a weight so gravity can affect it. Change its size to 0.5, 0.5, 0.5 and place its directly above the box you created earlier. The scene is now set up, we just need to add some interactivity through scripting. To create a script go to the insert menu and click on Inline Script, give it a name like 'OnCollision'. The script will then be added to the project list and by double clicking it will open up a scripting window. Now add this script in:
Remember to change the name of the element in the script to correspond with the name of your light. The only thing left now is to add a trigger to fire the script. Select the sphere and in its properties there is a menu called triggers. The first dropdown corresponds to the event you want it to occur on, we want "collided". The second dropdown is for your script, select it and click the + to add the trigger to the sphere.
That's it, now click Interactive Preview to watch your work in action. On collision events can be used for all sorts of situations, have a play with them and see what you can come up with. |

