Difference between revisions of "How to make an Object Clickable"

(Improved formatting)
Line 1: Line 1:
This is from a post Robert the Rebuilder made. Dumped here by Andy Legate : )
+
Given that you have an object in your scene (e.g. a book), this tutorial explains how to make it "clickable" - when you click on the book, it will trigger a script.
  
Here's some rough steps to get you going. [Note to self and others: there really should be a Wiki tutorial on this!]
+
You will first need to create a "click region" around your object. Below are the steps to create a click region:
 
+
# Choose Scripts->Add->PyPRP, then choose "Add a (Generic) Logic Region". It will appear in layer 2.
To create a click region:
+
# Select it, then move it to the place where the avatar will be standing when they attempt to click on the object.<br>[[Image:clickregion.jpg]]
- Choose Scripts->Add->PyPRP, then choose "Add a (Generic) Logic Region". It will appear in layer 2.
+
# Scale it so that it can encompass an avatar and the object that is clickable, then hit Ctrl-A to apply scale and rotation into the vertices.
- Select it, then move it to the place where the avatar will be standing when they attempt to click on the object
+
# Rename the object to something meaningful (e.g. MyClickRegion)
- Scale it so that it can encompass an avatar and the object that is clickable, then hit Ctrl-A to apply scale and rotation into the vertices
+
# On the Logic panel:
- Rename the object to something meaningful (e.g. MyClickRegion)
+
## Click on Bounds, then set it to "Convex Hull Polytope"  
- On the Logic panel, click on Bounds, then set it to "Convex Hull Polytope"
+
## Click the Actor button on the Logic panel
- Click the Actor button on the Logic panel
+
## Your Logic panel should look like this: [[Image:clickregionpanel.jpg]]
 
+
To make an object clickable:
+
- Select the object
+
- On the Logic panel, click on Bounds, then set it to "Convex Hull Polytope"
+
- Click the Actor button on the Logic panel
+
- Add the following AlcScript entry:
+
  
 +
Next, you need to prepare your object to be "clickable":
 +
# Select the object
 +
# On the Logic panel, click on Bounds, then set it to "Convex Hull Polytope"
 +
# Click the Actor button on the Logic panel
 +
# Add the following AlcScript entry:
  
 
     ObjectName:
 
     ObjectName:
Line 25: Line 24:
 
                 pythonfile: myPythonFile
 
                 pythonfile: myPythonFile
 
                 region: MyClickRegion
 
                 region: MyClickRegion
 
  
 
But change "ObjectName" to your object's name, "myPythonFile" to the name of your python file, and "MyClickRegion" to the name of your click region.
 
But change "ObjectName" to your object's name, "myPythonFile" to the name of your python file, and "MyClickRegion" to the name of your click region.

Revision as of 21:38, 25 April 2008

Given that you have an object in your scene (e.g. a book), this tutorial explains how to make it "clickable" - when you click on the book, it will trigger a script.

You will first need to create a "click region" around your object. Below are the steps to create a click region:

  1. Choose Scripts->Add->PyPRP, then choose "Add a (Generic) Logic Region". It will appear in layer 2.
  2. Select it, then move it to the place where the avatar will be standing when they attempt to click on the object.
    Clickregion.jpg
  3. Scale it so that it can encompass an avatar and the object that is clickable, then hit Ctrl-A to apply scale and rotation into the vertices.
  4. Rename the object to something meaningful (e.g. MyClickRegion)
  5. On the Logic panel:
    1. Click on Bounds, then set it to "Convex Hull Polytope"
    2. Click the Actor button on the Logic panel
    3. Your Logic panel should look like this: File:Clickregionpanel.jpg

Next, you need to prepare your object to be "clickable":

  1. Select the object
  2. On the Logic panel, click on Bounds, then set it to "Convex Hull Polytope"
  3. Click the Actor button on the Logic panel
  4. Add the following AlcScript entry:
   ObjectName:
       physical:
           pinned: true
       quickscript:
           simpleclick:
               pythonfile: myPythonFile
               region: MyClickRegion

But change "ObjectName" to your object's name, "myPythonFile" to the name of your python file, and "MyClickRegion" to the name of your click region.