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)
#How to make a pixel animation for attachables
1 messages · Page 1 of 1 (latest)
i think you need this maybe if I’m understanding what you trying to say correctly
Dont think this work on attachables unfortunately
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.
Yeah but then how can I do that without it looping
Just make a variable to use as the index of the array
What
You decide on the math that happens in it
Uh do you have an example for that? I've not done that before
At least not like this idt
Do you know about "initialize" and "pre_animation"?
A little not much
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.
Oh wow, thank you! I'll try this
One question, is there a query for the first time rendered thing?
Not really, You can use q.life_time for entities/attachables though, it will return 0 on the first frame they are rendered
Wait so you weren't implying using a query in what you wrote earlier? Sorry, i don't think i fully understand
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
Read the wiki guide I sent first before asking more questions!
Will do
Won't initialise only ever be able to run the animation only for once for the player itself, i.e. when they join the World and equip the armor for the first time
Because it does not seem to work beyond that
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.
I ended up using item equipment count to do it, thank you though your method was still very helpful!
Where did you use it exactly?
In the attachable file itself
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.
Yeah I can make the compromise, since I need the player to wear 4 Pieces of armor anyway