Animating an item from typescript or managing the same event both in CoBlocks and Script

Is it possible animating an item from typescript without using CoBlocks or Blockly?
If not, there’s a way for managing the same event both in CoBlocks and Script… i can’t succeed in this.

1 Like

Hi @mariochiesa,

do you mean playing an animation track of an item (ie. a human character), or do you mean moving the item position?

Hi @Stefan,
I can start an animation in CoBlocks, like choosing and customising a block to ‘set animation of man to Talking neutral’.
Can i start an animation through a script (Typescript odr Javascript)? This function is at least not documented…

My example:
I’m managing a slideshow totally in a Script, it works like a template… i’ve saved the script on my PC and i can copyit in a script in a new space, upload new images and soundclips, update the Ids in the template and everything works simple and fast. When i start playing a soundclip (typically a voice reading what is written in a slide… i’m testing VR for inclusive education…) it would be helpful to have the man start playing Talking neutral.

But this is just an example… controlling animation by scripts it would be very helpful in many situations…

@Stefan, sorry missed to ask this:
in the case i can control animations only in CoBlocks, can i have two events working on the same item and with the same event? like man.onActivate() in Script and ‘when man is clicked’ in CoBlocks?

Hi @mariochiesa,

the method onActivate and the CoBlock when item clicked are mutually exclusive. Only one of the two will be active at a time on a single item.

I like to share an internal method with you that allows you to play the animation track of an item. Please keep in mind that this method won’t be recognized by your code editor, but will still work. The animation name is case sensitive.

const myItem = Scene.getItem('myItemName') as AnimatedItem;
myItem.animation.playLooping('myItemAnimation');
2 Likes

Hi
all these methods are deprecated is there a plan for new ones
Thx Zohar

Hi @Ohalo_Innovation,

Below you can find a space that demonstrates the latest API for controlling animation and events on items. Feel free to remix it to see how the script works :slight_smile:

1 Like

it is not possible to remix only the link is shared
Zohar

Hi @Ohalo_Innovation,

Please make sure that you are logged into CoSpaces Edu (e.g. via another browser tab) when opening the space above. Also note that remixing is only possible for Cospaces Edu PRO users.