Trying to do Marco Polo with approach but baby keeps crying...
Sorry for dumb debug but I am home alone looking after baby so it's
1)feed;
2)change;
3)soothe;
4)code ;
5 goto 1;
trying to use the approach on animate tutorial to make a simple peek-a-boo or marco polo lens..
getting no errors but not able to get the function boo to run i think i messed up the approach part.
also I don't think you need the manipulate part unless you are wanting to have the 3object rotate spin etc?
If anyone can see what I missed.
// @ui {"widget": "group_start", "label": "Peek-a-boo Settings"}
// @input SceneObject object1
// @input SceneObject cameraObject
// @input float triggerRadius
// @ui {"widget": "group_end"}
//var setups for approach for peek a boo..
var minManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").minDistance;
var maxManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").maxDistance;
script.triggerRadius = clampNumber(script.triggerRadius, minManipDist, maxManipDist);
//the function to hide object
function peeka(){
script.object1.enabled = false;
}
//the function to show object
function Boo(){
script.object1.enabled = true;
}
// inital function reset on lens start
function onLensTurnOnEvent()
{
peeka();
}
var turnOnEvent = script.createEvent("TurnOnEvent");
turnOnEvent.bind(onLensTurnOnEvent);
// end of start and reset
// the Function that runs on every frame for checking the distance
// Function runs at the start of every frame if not in radius of collission make sure object is hidden with peeka function
function onUpdateEvent(eventData)
{
if(script.cameraObject)
{
// Distance between the camera and the object is used to determine when to trigger the approachs hiddne status
var dist = script.cameraObject.getTransform().getWorldPosition().distance(script.getSceneObject().getTransform().getWorldPosition());
// If the object isn't hidden hide it
if(dist <= script.triggerRadius)
{
peeka();
}
}
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdateEvent);
// end of function frame start
// clean up on lens turn off
function onLensTurnOff()
{
peeka();
}
var turnOffEvent = script.createEvent("TurnOffEvent");
turnOffEvent.bind(onLensTurnOff);
// Function for handling approachs peek a boo
function onApproach(eventData)
{
if(global.scene.getCameraType() == "back")
{
print("Peekaboo");
boo ();
}
}
// Clamping number utility function //picked up from approach un-sure of use.
function clampNumber(val, min, max)
{
return Math.min(Math.max(val, min), max);
}
-
This post can be deleted I just re-invented the wheel here...not even a nice looking wheel!!
with this you can use seperate animation and audio (def needs some TLC!)
// @ui {"widget": "group_start", "label": "Peek-a-boo Settings"}
// @input SceneObject object1
// @input SceneObject cameraObject
// @input float triggerRadius
// @ui {"widget": "group_end"}
//var setups for approach for peek a boo..
var minManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").minDistance;
var maxManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").maxDistance;
script.triggerRadius = clampNumber(script.triggerRadius, minManipDist, maxManipDist);
//the function to hide object
function peeka(){
script.object1.enabled = false;
}
//the function to show object
function Boo(){
// @ui {"widget": "group_start", "label": "Boo reveal Settings"}
// @input SceneObject objectboo
// @input Component.AnimationMixer animationMixer1
// @input string animationLayerName1 = "BaseLayer"
// @input float animationWeight1 = 1.0 {"widget":"slider", "min": 0, "max": 1, "step": 0.01}
// @input float animationStartOffset1 = 0.0
// @input int numberOfLoops1 = 1
// @ui {"widget": "group_end"}
// @input Component.AudioComponent audioRex
script.audioRex.play( 1 );
script.objectboo.enabled = true;
if(!script.animationMixer1)
{
script.animationMixer1 = script.getSceneObject().getFirstComponent("Component.AnimationMixer");
}
if(script.animationMixer1)
{
script.animationMixer1.setWeight(script.animationLayerName1, script.animationWeight1);
script.animationMixer1.start(script.animationLayerName1, script.animationStartOffset1, script.numberOfLoops1);
}
}
// inital function reset on lens start
function onLensTurnOnEvent()
{
peeka();
}
var turnOnEvent = script.createEvent("TurnOnEvent");
turnOnEvent.bind(onLensTurnOnEvent);
// end of start and reset
// the Function that runs on every frame for checking the distance
// Function runs at the start of every frame if not in radius of collission make sure object is hidden with peeka function
function onUpdateEvent(eventData)
{
if(script.cameraObject)
{
// Distance between the camera and the object is used to determine when to trigger the approachs hiddne status
var dist = script.cameraObject.getTransform().getWorldPosition().distance(script.getSceneObject().getTransform().getWorldPosition());
// If the object isn't hidden unhide it
if(dist <= script.triggerRadius)
{
Boo();
print("Peeka-hide");
}
}
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdateEvent);
// end of function frame start
// Clamping number utility function //picked up from approach un-sure of use.
function clampNumber(val, min, max)
{
return Math.min(Math.max(val, min), max);
}
Comment actions -
Awesome, glad you found a solve!
FWIW, I did write a simplified approach script a while back that can work outside the template. Might be worth looking at. It's very similar to what you are doing.
// @input Component.SpriteVisual spriteBefore
// @input Component.SpriteVisual spriteAfter
// @input SceneObject cameraObject
// @input float triggerRadius
// Function runs at start of lens
function onLensTurnOnEvent()
{
approached = false;
script.spriteBefore.enabled = true;
script.spriteAfter.enabled = false;
}
var turnOnEvent = script.createEvent("TurnOnEvent");
turnOnEvent.bind(onLensTurnOnEvent);
function onUpdateEvent()
{
if(script.cameraObject)
{
var dist = script.cameraObject.getTransform().getWorldPosition().distance(script.getSceneObject().getTransform().getWorldPosition());
if(!approached && dist <= script.triggerRadius)
{
onApproach();
}
}
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdateEvent);
function onApproach()
{
if( !approached )
{
print( "APPROACHED" );
approached = true;
script.spriteBefore.enabled = false;
script.spriteAfter.enabled = true;
}
}Comment actions -
Oh also a little tip, the editor on the forum if you click the little Paragraph icon has a "Code" formatting style. This might make you code show up a little cleaner in your forum posts. Sometimes I still have to fix some tab / spaces problems. But it generally does a good job.
Comment actions -
Hey Travis, once again thank you for advice and writting cleaner code
have also edited my post to "code"
Comment actions -
I recently created the baby lens and its looking very nice I tried it and you can visithere to experience it.
Comment actions
Please sign in to leave a comment.
Have a comment?