Shrink Object's Scale on Custom Trigger

Hi, I’m trying to learn how to change object’s transform by using Custom Trigger. But it gives me an error and I don’t know how it should be to fix it.

this is the error:

So basically what I want to achieve is that every time the custom trigger is calling (in this case I just use screen tap as the custom trigger from behavior script), the plane 2’s Y scale (blue) is decreasing 0.1 until 0. Can someone help me?

This is the project file.
Tap to Shrink Scale.zip (2.5 MB)

I think line 8 should be new vec3(...), not just vec3(...)


still throwing out an error :frowning:

You might want to try using the sub() function rather than -=

vec3 API reference




how to write that down? an exact example would be more helpful. cuz I’ve gone to that page hours ago and tried all of the above combination but still error.

I can’t test anything right now, but it’s probably going to be var newScale = scale.sub(new vec3(0, 0.1, 0));

tried that, still not working :smiling_face_with_tear:

I gave it a try using a tap event and with your current setup it will only do the shrinking once, but the sub function as above is correct. The following script will cause whatever object the script is attached to to shrink on each tap.

script.createEvent("TapEvent").bind(function() {
    var transform = script.getTransform();
    var scale = transform.getLocalScale();
    var newScale = scale.sub(new vec3(0, 0.1, 0));
    transform.setLocalScale(newScale);
});
1 Like

Sorry for the super late response and thanks for the example code! It works now, but I don’t use this function: script.createEvent(“TapEvent”).bind(function()
because like I said, I want the trigger is a custom trigger. And that tap in my example is simply just to debug. but the next lines are just like what you show before.

This is the script that I ended up using:

// -----JS CODE-----
global.behaviorSystem.addCustomTriggerResponse("SHRINK", Shrink);



function Shrink() {
    var transform = script.getTransform();
    var scale = transform.getLocalScale();
    var newScale = scale.sub(new vec3(0, 0.1, 0));
    transform.setLocalScale(newScale);
};

simply drag n drop the script to inspector of the plane.
and set behavior script to generate the custom trigger called SHRINK in the other scene object.

can’t wait to show the final effect that uses this mechanics. I’ll share the effect link here when it’s done.
Once again, thank you!!!

1 Like