Hurt Animations

intermediate

This guide will teach you to trigger custom hurt animations for entities. There is no really good way to make custom hurt animations as for now (at least from I know).

BP Entity Part

First you need to setup entity file. Make sure to use file version that supports properties.

Add the following to entity description:

BP/entity/my_entity.json#descriptionCopy
json
"properties": {
    "wiki:is_hurt": {
        "client_sync": true, // so we can use it in RP
        "type": "bool",
        "default": false
    }
}
1
2
3
4
5
6
7

And this in component groups:

BP/entity/my_entity.json#component_groupsCopy
json
"wiki:hurt_group": {
    "minecraft:timer": {
        "time": 0.1,
        "time_down_event": {
            "event": "wiki:on_not_hurt_event"
        }
    }
}
1
2
3
4
5
6
7
8

Events to add this component group and switch properties:

BP/entity/my_entity.json#eventsCopy
json
"wiki:on_hurt_event": {
    "set_property": {
        "wiki:is_hurt": true
    },
    "add": {
        "component_groups": [
            "wiki:hurt_group"
        ]
    }
},
"wiki:on_not_hurt_event": {
    "remove": {
        "component_groups": [
            "wiki:hurt_group"
        ]
    },
    "set_property": {
        "wiki:is_hurt": false
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

To call this event add damage_sensor to components:

BP/entity/my_entity.json#componentsCopy
json
"minecraft:damage_sensor": {
    "triggers": {
        "cause": "all",
        "on_damage": {
            "event": "nubs:on_hurt_event"
        }
    }
}
1
2
3
4
5
6
7
8

RP AC Part

You can transition to state with hurt animation this way: "damage_state": "q.property('wiki:is_hurt')" and from there use "default": "q.all_animations_finished".

This could be useful for creating custom boats.

Contributors