Script examples in the gallery or elsewhere?

Hi all,

First off - please forgive me if I seem to be asking for the obvious - I am new and try hard to look for answers to my questions before posing them here. I have looked and not or hardly found so here is my question:

Are scripted examples somehow marked in a specific way so they can be recognised?
Is there perhaps a separate collection somewhere for scripted examples?

I am already studying the API documentation. Coded examples would help a lot.

So if you have some examples/pointers ? Please . Much obliged

Hi @Frank_Claessen,

Unfortunately, we do not have that tag at the moment.
You can find a few examples here, on the forum Coding section or ask your questions if you have any

Hi - I was going to try to find this same question - as I’m going to be getting into a 2 week intense course with some high school students and the team wanted to use Typescript vs the Coblocks. So now I have to learn typescript!!

Would love to find some tutorials me to learn or to share with my students. If not, doesn’t anyone have suggestions on where to get started?

https://www.typescriptlang.org/

I just did some of my own learning 2 weeks ago to help HS Students. I found the CoSpaces API pretty good once you find your way around. The Script also has API suggestions now while typing which helped me a lot.

Start the by right clicking the item and grabbing the ‘Scene.getItem()’ and setting it to a variable. The AutoFill will set it as an Animated Item. All the Animated Item methods can be found on this page: https://cospaces.io/api/classes/animateditem.html

The animation section will teach animations playing and stopping, The transform section teaches positions. The Transitions teaches movement code. OnCollisionEnter/Exit is there too on this page, as well as speech/thought syntax.

This is where it started to make more sense to me.

1 Like

Thanks for that insight - I have spend a few hours today explore and I was able to have my Rabbit say Hi and animated (based on the examples) but now I’m having trouble moving the Rabbit around. I will try some more but since I’m new to Typescript and Javascript - I’m not sure how long I can last with this. I’m not used to reading documentation and putting it into action - I need examples to help me. @Ryan_Noonan_DETNSW Would you give me a demo? or a few starter videos?
@CoSpacesEdu - Are there some lessons or anything done in coding script or is it all in CoBlocks?

Many many thanks in Advanced

1 Like

I don’t have any videos on it. This is where you want to read from: https://cospaces.io/api/classes/animateditem.html#transition

Transition is what I’ve used so far to move characters. I find it way easier to use the moveTo() function to start with. The moveBy() function would be another option.

Example:
let tRex = Scene.getItem(“Ak0UUX5o”) as AnimatedItem;
let goal = Scene.getItem(“6aecAexw”) as AnimatedItem;
let goalPos = goal.transform.position;

tRex.transform.lookAt(goalPos);
tRex.transition.moveTo(goalPos, 5);

That will move the TRex in a line towards a goal taking 5 seconds while continuing to rotate the front towards a goal.

Hope that helps a little.

There is also a physics system I haven’t touched yet that appears to have applyForce(), applyImpulse() and Velocity() which I presume is another way to move characters. Maybe someone can give examples of movement using the physics system?

1 Like

Thanks for that little example - it has give me so much to work with to get the students started with moving objects around the environment.

My next goal will be to move my T-Rex around a path!