If we label an object with text floating above it and we want the text readable from anywhere we go, not just one position looking straight on, we need the text to move when the default camera(when playing on computer) or the VR Rig's VR camera moves. If the camera moves, the text should swivel to face that camera. We have a built in function that ensures that one object points at another; its called "Look At", or the lookAt() function. When A looks at B, A rotates to face B. This works for any object not just text. Let's set it up.
1. OPEN THE ON-TICK FUNCTION SCRIPT ON THE TEXT:
- Select a text entity in your space.
- Open the property editor in the top right.
- Select TextEntity at the top of the left property pane
- Select the Events property on the lower part of the right pane.
- Click the underlined words onTick()
- This will open up the onTick() function for the object in the script editor.
- Note: this onTick() function is called every frame when you play/present a Simmetri show. This could be hundreds of times a second, something to keep in mind when we make really complicated scripts, but its nothing to worry about at this point.
2. INSERT THE "LOOK AT" SCRIPT:
In the onTick() function you should be seeing:
function MeshEntity:onTick() end
- You'll want to enter the following script into the function, between the first line
function MeshEntity:onTick()
and the last line,end
:
Insert this script:
self:lookAt(self:getSpace():getDefaultView():getWorldPosition())
Your final function should look like this:
function MeshEntity:onTick() self:lookAt(self:getSpace():getDefaultView():getWorldPosition()) end
3. TEST IT OUT:
- Press play.
Not Quite Right!
- You might not see it at all.
- Hmmmm... it appears the Text Entity is rotating to follow the camera.. but its not rotated quite right. Lets get its base rotation fixed.
4. FINE TUNE THE BASE ROTATION:
- Select the text entity again and return to the Property Editor
- Under MeshModel on the left property pane, select Mesh Modifiers.
- Click the plus(+) button at the bottom of Mesh Modifiers pane and select VertexTransform.
- Adjust the Rotation to face the camera in the selected VertexTransform menu:
- Set X = -90, y = 0, and z = 180
HOW THIS SCRIPT WORKS
- If the text entity could talk out this function, it would say:
"On every frame, I will look at the default camera in my space."
- That's what contained in this function.
function MeshEntity:onTick() self:lookAt(self:getSpace():getDefaultView():getWorldPosition()) end
- "On every frame" that's
onTick()
- "I will" that's what
self
means:self
refers to the text object itself, because its a function called in the scope of this text object in itsonTick()
function. - I will
lookAt()
a point in space. - What point? The point in space that's inside the
()
parentheses afterlookAt
. - Look at the "default camera"... technically, look at its exact position in space at every frame. What do we want the text object (
self
) to look at? Well, theworldPosition
of thedefaultView
of theSpace
the object is in. This is a series of 'get' functions that give you back the world position of the default camera in the space.
Comments
0 comments
Please sign in to leave a comment.