#How to make a pixel animation for attachables

1 messages · Page 1 of 1 (latest)

strange hare
#

I want to be able to play an animation that is a pixel like animation that happens on armor when I equip it, (through scripts or any other methods you may know of that you think could work), I know how to loop a pixel animation, but I dont know how to play it just once, and then have the armor look normal. (For eg: If I explained it poorly, how nanotech on like an iron man suit would be equipped)

coarse knoll
strange hare
dapper granite
#

The UV_anim material property does not work on attachables.
But you can work around that by preparing one texture per frame, and switch them in the attachable RC.

strange hare
dapper granite
#

Just make a variable to use as the index of the array

strange hare
#

What

dapper granite
#

You decide on the math that happens in it

strange hare
#

At least not like this idt

dapper granite
#

Do you know about "initialize" and "pre_animation"?

strange hare
dapper granite
#

https://wiki.bedrock.dev/entities/entity-intro-rp#scripts A guide you should read on initialize and pre_animation in general, it works the same on attachables as on entities.

To make a simpler version of what you want, you can make it so the texture animation happens when the piece of armor is first rendered. That's not exactly the same as only when it is put on (it will play when you open the map when you already have the armor on, and when you start rendering other players), but it's a good start.

#

After preparing the frames of the texture animation as different textures, you should list them all in your attachable file in the right order, and make an array in the custom Render Controller for the attachable to use them. No UV animation will be involved, just switching which texture of the array is going to be used by the attachable.

If you have "textures": ["array.textures[0]"] in the RC, it will use the first texture you listed in the array. If you have"textures": ["array.textures[2]"], the third. Instead of a fixed number, you'll be able to use a variable, like "textures": ["array.textures[v.texture_index]"]. This variable is created on the attachable file. You can create it with just initialize, but to change it over time you'll need pre_animation.
Depending on the order of the animation, you'll make it start to use the first frame or the last frame.

If you start at 0 in initialize "v.texture_index = 0;", you can make it grow in pre_animation with v.texture_index = v.texture_index + q.delta_time;. pre_animation will run one every frame that is rendered, so if you have 30 FPS, that's 30 times a second, if you have 60FPS, 60 times a second.
So every frame, the variable will add to itself the time since the last frame (that's what q.delta_time is, at 60 FPS it will return around 0.05. It's important to use q.delta_time instead of a fixed number, otherwise the speed of the animation won't be the same depending on the device's framerate).

You can clamp the variable so that the value never goes past the number of frames, like v.texture_index = math.clamp(v.texture_index + q.delta_time, 0, 9);
And you can speed up or slow the animation by multiplying q.delta_time: v.texture_index = math.clamp(v.texture_index + 2 * q.delta_time, 0, 9); for twice as fast; v.texture_index = math.clamp(v.texture_index + 0.5 * q.delta_time, 0, 9); for twice as slow.

strange hare
#

One question, is there a query for the first time rendered thing?

dapper granite
#

Not really, You can use q.life_time for entities/attachables though, it will return 0 on the first frame they are rendered

strange hare
dapper granite
#

only q.delta_time

#

Initialize will run automatically when the attachable is first rendered, so no need to query when the attachable is first rendered

strange hare
#

Ohhhh

#

Ok i think I got it, I'll try it out now

dapper granite
#

Read the wiki guide I sent first before asking more questions!

strange hare
#

Will do

strange hare
#

Because it does not seem to work beyond that

dapper granite
#

Attachables seem to be still loaded on the player if they do not start wearing another attachable item in the same slot. So their variables are saved, and initialize won't run again, you're right.

You may be able to trigger the item cooldown when you start wearing it with scripting, to detect when that happens with https://bedrock.dev/docs/stable/Molang#query.cooldown_time or https://bedrock.dev/docs/stable/Molang#query.cooldown_time_remaining in a variable of the attachable.
Not sure whether you can have a cooldown on an armor piece though.

strange hare
dapper granite
strange hare
dapper granite
#

And it works when you wear a single piece of armor, remove it and put it back on? I thought when you did not wear the attachable, its variables won't update. Won't it return just 1 all the time?
I get how it would change on other armor pieces if you were wearing several, and removed / put on one.

strange hare