#Weird position offsets in vanilla entity animations

1 messages · Page 1 of 1 (latest)

tender nova
#

I'm making a Minecraft world exporter, where I'm currently working on adding support for Bedrock edition. It's basically all done. I've added in that it can also simulate and animate entities based on the data from the resource packs and behaviour packs.

I'm testing it out with some vanilla entities and it's all working, but some mobs don't show up the same as in Minecraft. For example, the heads of sheep are moved down.

When I look at the animations for sheep, I find this ```JSON
"animation.sheep.setup" : {
"loop" : true,
"bones" : {
"body" : {
"rotation" : [ "-this", 0.0, 0.0 ]
},
"head" : {
"position" : [ 0.0, "-6.0 - this", 0.0 ]
}
}
}

Which is the cause for the sheep's head to be moved down, but this animation is also applied in vanilla Minecraft, yet it doesn't move the sheep's head downwards.

Another example is polar bears. Polar bears are sunk into the ground. And again, then looking through the animation files I find this: ```JSON
"animation.polarbear.move" : {
    "loop" : true,
    "bones" : {
        "body" : {
            "position" : [ 0.0, "-9 - 2 * query.standing_scale - this", 0.0 ],
            "rotation" : [ "(-(query.standing_scale) * 63) - this", 0.0, 0.0 ]
        },
        "leg0" : {
            "position" : [ 0.0, "-1 * query.standing_scale", "6 * query.standing_scale" ],
            "rotation" : [ "query.standing_scale * 63", 0.0, 0.0 ]
        },
        "leg1" : {
            "position" : [ 0.0, "-1 * query.standing_scale", "6 * query.standing_scale" ],
            "rotation" : [ "query.standing_scale * 63", 0.0, 0.0 ]
        },
        "leg2" : {
            "rotation" : [ "(query.standing_scale > 1) ? (query.standing_scale * 81) - this : 0", 0.0, 0.0 ]
        },
        "leg3" : {
            "rotation" : [ "(query.standing_scale > 1) ? (query.standing_scale * 81) - this : 0", 0.0, 0.0 ]
        }
    }
}

Which moves the body down by 9 units, causing it to sink into the ground.

I thought maybe it's something hardcoded, but in the minecraft-samples repository there are some example addons and this one has a black bear entity which is basically a copy of the polar bear. It also has the same animation as the polar bear, including the -9 on the body's position. So my exporter also moves it down, yet in Minecraft it shows up correctly.

So, there's something that Minecraft is doing that isn't documented anywhere or I missed something. I'm just a bit at a loss at what I'm missing.

Does anyone here have a clue at what's going on?

GitHub

Contains custom add-on samples for Minecraft Bedrock Edition. - microsoft/minecraft-samples

cunning dome
#

Could be related to this keyword. It represents a total value for all animations evaluated preciously in the frame. See explanation here #1067870133328027730 message

last carbon
#

I’m sorry I really don’t. But I have had similar issues

tender nova
#

I've thought about it maybe being related to the this keyword, but the molang expressions all have -this which would effectively clear whatever value had been accumulated at that point (reset it). So it shouldn't matter what value had been accumulated so far or what value it started at. Unless this works differently that how I've come to understand it

cunning dome
#

Yeah you're right, so if your program doesn't clear the value, previous animations might be interfering with offset animation, by adding together their transform, while in vanilla, offset animations override transform of previous anims whenever -this is used. Easy way to check is to remove -this from vanilla animations and see if they also break in-game, in the same or similar way

tender nova
#

Okay, so if I remove -this from the animation file, then it shows up the same as in my program. So this is set to something. I tried this in the black bear entity, which is a copy of the polar bear. That animation file has the following expression -9 - 2 * query.standing_scale - this Getting rid of the - this moves the black bear down. Getting rid of the -9 as well, moves it back.

However, when looking at all of the files for the black bear (which again is just a copy of the vanilla polar bear), then the order in which the animations occur is animation.black_bear.walk, animation.black_bear.move, animation.common.look_at_target, animation.black_bear.baby_transform

animation.black_bear.walk doesn't change the body bone. animation.black_bear.move does using the expression above, and the other two also don't affect the body bone. So the only animation that affects the body bone, is the move animation which has the weird expression.

Shouldn't the bone's values be reset at the start of the frame and then the animations get evaluated? In that case, since animation.black_bear.move is the first animation to specify the body bone, shouldn't this then be 0.0? Unless the body bone's bind pose has it's position Y set to -9.0 by default, but I have no idea where that number would come from

#

The model file does specify a pivot, but as far as I'm aware that shouldn't affect the bone's bind pose's position. ```JSON
{
"name": "body",
"pivot": [-2, 15, 12],
"cubes": [
{
"origin": [-7, 14, 5],
"size": [14, 14, 11],
"pivot": [0, 15, 12],
"rotation": [90, 0, 0],
"uv": [0, 19]
},
{
"origin": [-6, 28, 5],
"size": [12, 12, 10],
"pivot": [0, 15, 12],
"rotation": [90, 0, 0],
"uv": [39, 0]
}
]
},

cunning dome
#

Yeah there are no other animations playing. Seems like this gets assigned some non-zero value, potentially from the geometry. Ik this for rotation is the sum of all rotation animations + initial rotation from the geo, so maybe something similar is happening here. Perhaps related to body pivot and/or old format version, which does things differently. I checked the value of this for sheep animation and it's equal to -6, for bear it's -9

#

Might be worth trying to change different things in the RP and BP, like geometry, scale, hitbox etc and see which one affects this

#

If u have an animation like this == -9 ? 100 : 0 that'd allow you to easily check when the value changes

tender nova
#

Good shout the this == -9 ? 100 : 0! Looks like changing the pivot in the model file affects it. Now it's just trying to see what's the logic behind it, since the pivot is [-2, 15, 12] yet this gets set to -9

#

Hmmm.
Pivot Y : this
15 : -9
16 : -8
17 : -7
14 : -10
13 : -11

So pivotY - this = 24

#

or pivotY - 24 = this

#

Similar for the X and Z axis, but then it's just the pivot value. So the bind pose's position is equal to the pivot and that's the value that it gets reset to at the start of every frame. Yet the Y value has some offset to it

#

That offset also seems to be the same for the sheep's head, since it's pivotY for the head is 18, which 18 - 24 = -6 which matches what we see in the animation file

#

But then where does the -24.0 offset come from

cunning dome
#

Could be hardcoded for a specific format version

#

or there is something else that affects it. I'd recommend changing every other value that you can think of both in BP and RP except for pivot and see if that affects it. If not, then try updating format versions of all files related to this entity and see which file and version adds that offset

tender nova
#

Seems to be the case for all format versions, so I'm just going to assume that it's some hardcoded value. Maybe that it came from the player model, since the head's pivot is [0, 24, 0].

Anyways, thanks for the help Veka! I really appreciate it!

cunning dome
#

Gl with your project