Intersecting Objects trigger not working when using Javascript to move character
Feb 24, 2023
I am using javascript in Storyline 360 to move an animated character on key press, which is working really well. I would like to trigger a layer when the character intersects with certain portions or other objects of the scene. For some reason, adding an "Object intersect" trigger is not working. Below is a sample of the code I am using. This action moves the character to the left. Any suggestions would be helpful.
var player = GetPlayer();
let bGirl = document.querySelector("[data-acc-text='BGirlStanding.gif']");
let bGirlMoveX = gsap.getProperty(bGirl, "x");
let bGirlMoveY = gsap.getProperty(bGirl, "y");
let maxWidth = player.GetVar("pgWidth");
let currentX = player.GetVar("bGirlX");
let maxHeight = player.GetVar("pgHeight");
let currentY = player.GetVar("bGirlY");
let moveY = (0);
let exit = (0);
if (currentX > 0)
{
moveX = (-100);
}
else
{
moveX = (0);
newExit = player.GetVar("exit");
player.SetVar("exit",newExit+1);
}
gsap.to( bGirl, { duration:0.25 ,x:bGirlMoveX+moveX,y:bGirlMoveY+moveY});player.SetVar("bGirlX",bGirlMoveX+moveX);
player.SetVar("bGirlY",bGirlMoveY+moveY);
2 Replies
If you use GSAp it doesn't support the built in triggers to know that the object has been moved so intersect will not work. You will need to add a listener to check for position and then increment a variable to show the layer.
What might that look like?