#Another Method for Running Animations from Attachables (and Better)

1 messages · Page 1 of 1 (latest)

wanton thunder
#

Triggering Attachable Animations from Scripts (and Better)

First step: Create variables in the attachable

We need to create 3 variables:

A BP variable (the one we'll send from the resource pack)
A temporary variable
A variable for the resource pack (for animations, animation controllers, or render controllers, whatever)

First: Create the variables in the pre_setup.

Here we will assign the temporary variables and those of the "bp"
Example:

// t.bp_animation = is the temp variable bp_**
// v.bp_animation = is the bp variable bp_**
"parent_setup": "t.bp_animation = v.bp_animation ?? 0.0;", // We put "?? 0" so that Minecraft doesn't throw an error in the log

Another example:

// To assign multiple variables, do it this way; you can change 0.0 to another value to assign the default value.
"parent_setup": "t.bp_animation_1 = v.bp_animation_1 ?? 0.0; t.bp_animation_2 = v.bp_animation_2 ?? 0.0; t.bp_animation_3 =  v.bp_animation_3 ?? 0.0;",

Second: Create the variables in the initialize:

Here we only need to create the RP variables

                "initialize": [
                    "v.rp_animation_1 = 0.0;", // rp_**
                    "v.rp_animation_2 = 1.0;",
                    "v.rp_animation_3 = 2.0;"
                ],

Third: Transfer the values ​​of the BP variables to the RP variables (using the temporary variables)

This is where the magic happens, and now the RP variables are useful and usable.
Example:

                "pre_animation": [
                    "v.rp_animation_1 = t.bp_animation_1 ?? 0.0; v.rp_animation_2 = t.bp_animation_2 ?? 0.0; v.rp_animation_3 = t.bp_animation_3 ?? 0.0;"
                 ],
#

Congratulations! You're halfway there; the attachable is ready to receive variables. Now, how do we send them?

There are two methods:

Method 1: Animation

You can send the values ​​using animations like this:
This allows you to run the animation from anywhere within the "bp"; anything that can run the animation will change the variables for the attachable.

        "animation.set_animation_init": {
            "loop": "hold_on_last_frame",
            "timeline": {
                "0.0": "v.bp_animation_1 = 1.0;" // bp_** is a bp var
            }
        },
#

Method 2: Scripts and Dummy animation

From the RP you will have to create a dummy animation that will allow us to send all the variables to a specific player.

{
    "format_version": "1.10.0",
    "animations": {
        "animation.sny.dummy_animation": {
            "animation_length": 0.05
        }
    }
}

And now, from the BP, we will dynamically send the information to the player using scripts.
We will use this example function (or you can create your own if you prefer)

import { Player } from "@minecraft/server";

export function setTempVars(player, data) {
    if (!(player instanceof Player)) return;
    const random_1 = (Math.random() * 1e3) << 0;
    const dataEntries = Object.entries(data)
        .map(([key, value]) => `v.bp_${key}=${JSON.stringify(value)};`)
        .join("");
    const stopExpression = 
        dataEntries +
        `return 0;`;
    player.playAnimation("animation.sny.dummy_animation", {
        controller: "animation_controller_set_"+random_1, // If you don't add the random variable, it won't work correctly; it shouldn't generate memory leaks.
        stopExpression,
    });
}

Example of use:


let a = 0

world.afterEvents.playerButtonInput.subscribe(({button,player})=>{
    if (button !== InputButton.Jump) return;
    a++
    setTempVars(player,
        {
            animation_1: a%2 // Without the bp_**, the function already adds it automatically.
        }
    )
})

Credits for the system improvement: Me and @tiny kiln

snow moat
#

wawawa this is very helpful

cyan bronze
#

U could do this a lot easier by just using properties

zealous laurel
#

nobody wants to do that

#

btw I discover you can do this easier by just using two dummy animations```js
player.playAnimation(animation.dummy1, { controller: dummy, stopExpression: t.player_name = '${player?.name}'; t.hide_bone = true; return true; })

system.runTimeout(() => {
player.playAnimation(animation.dummy2, { controller: dummy, stopExpression: t.player_name = '${player?.name}'; t.hide_bone = false; return true; });
//another dummy animation it should be different to the previous one
}, 60);```

Attachable: json "animations": { "hide_bone": "animation.hide_hook" }, "scripts": { "initialize": [ "v.hide_bone = false;" ], "pre_animation": [ "q.get_name == (t.player_name ?? '') ? {v.hide_bone = t.hide_bone;};" ], "animate": [ { "hide_bone": "v.hide_bone" } ] }

#

this is a lot shorter code and it works

cyan bronze
civic peak
#

oh this is super smart!

split token
#

ty

civic peak
gusty dust
wanton thunder
gusty dust
#

i have it in player.json

cyan bronze
#

this is rly good for player to attachable communication without manipulating player.json

#

but if ur using an entity json instead might as well use properties

gusty dust
cyan bronze
gusty dust
split token
#

is it possibble to make custom rightArm animation through attachable?

rotund vale
civic peak
civic peak
#

nvm, figured out

steady drum
wanton thunder
steady drum
#

i will still be careful with that tbh

#

those controls are still there, and each call basicly make a new one

zealous laurel
steady drum
steady drum
#

yeah that works, but not dynamic

frosty blaze
#

Interesting.

zealous laurel
wanton thunder
merry mantle
grand echo
#

Ok, I would need some assistance with it.. Im trying to do this, but i dont know if trigger this in attachables can work. also what does or what is the function of the "controller" option in playAnimation??