I decided that I wanted to create a door which an avatar could open and close buy touching it, so I set off on building a wall with a door in the middle.
![]() |
| First step to building a door |
My next step was to create a hinging point for my door as by default the rotation point of any object is the middle and this is not how a door actually works is it?
![]() |
| Adding the hinging point |
Now to join these two objects together in Second Life, you must 'Link' them together by holding down the shift button and selecting the two (or more if you like) objects and finally click Ctrl + L to link them.
It's important to keep in mind that the last object you select will be the root object, therefore I selected the hinging point as the root.
So now I've got a wall with a door in the middle set up with a hinging point, true it's not the nicest looking thing you've ever seen but I decided to leave the looks for the end.
To test if I've done this correctly I first tried changing the rotation of the door via the Building Tools window, by setting a -90 degree value in the 'Z' parameter of the rotation fields and to my surprise...it actually worked!!
No, I'm lying, I had to try it about 5 times until I got it right...which is quite frustrating. But eventually it worked and this is how it looked like:
![]() |
| Manually opened door |
But now I wanted to create a script which does this every time a user touches the door, so after doing some research I learnt that you must do this by using the rotation variables of an object.
Every object has 4 rotation values; X, Y, Z and S but to make a door open all I needed to use were the Z and S values.
So I started out by retrieving it's Z and S rotation positions. I did this by writing a script which would get these values and output them on screen every time the object is touched.
The above script is what I'm taking about, it get these values by using the method 'llGetLocalRot()', this method returns an object of type "rotation", which contains all 4 values which I have previously mentioned, then it uses the method 'llSay()' to output the values I require on the screen using channel 0 (zero).
Back to getting those all important rotation values, I close the door once again and touched it to output it's Z and S values like so:
![]() |
| Rotation Variables |
I also did this for when the door is opened, so that I know how much I should open it and wrote these values done for now.
Then I re opened the object's script, removed the entry state as I don't need it and left the touch_start state. in here I used an IF statement which would check if the door is closed and open it. If the door is opened instead it closes it by setting the object's rotation variables to the ones I had written down by using the method 'llSetLocalRot()' and passing it the rotation variable which I modify.
![]() |
| Open-Close Door Script |
After playing around with some textures this is the final result:
![]() |
| Finished opening & closing door |
Conclusion
I must admit I don't quite think the LSL scripting language is one of the best scripts out there but at least with a few lines of code you can visually see things move around or for my last post's case, send an email with by simply using 'llEmail' this fact forces me to admit that I kind of enjoyed doing this today.







No comments:
Post a Comment