This is an example of how to enable flying control for entities in Minecraft Bedrock Edition using minecraft:input_air_controlled.
To enable control in the air, we add the minecraft:input_air_controlled component:
Located at Line ~209 in the minecraft:pig_saddled group:
"minecraft:input_air_controlled": {
"strafe_speed_modifier": 1,
"backwards_movement_modifier": 0.5
}Normally, this component only works on hover entities (those with movement.hover),
not with typical ground entities using movement.basic or movement.generic.
We bypass this limitation by dynamically toggling gravity and switching movement-related components using custom events (fly and walk) when a rider enters or exits the entity.
Note : this is for non movement.hover if your entity already has that component you dont need this
Located at Line ~13 in component_groups
"walk": {
"minecraft:physics": {
"has_gravity": true
}
}
"fly": {
"minecraft:physics": {
"has_gravity": false
},
"minecraft:flying_speed": {
"value": 0.0833333
}
}Function : We use this component groups to remove and restore gravity
Located at Line ~183 in component_groups.minecraft:pig_saddled:
"minecraft:rideable": {
"seat_count": 1,
"interact_text": "action.interact.ride.horse",
"family_types": [
"player"
],
"seats": {
"position": [
0.0,
0.63,
0.0
]
},
"on_rider_enter_event": "fly", // Call fly event on enter
"on_rider_exit_event": "walk" // Call walk event on exit
}Function : We use this to call fly and walk events
Located in the events section — Line ~349:
"fly": {
"add": {
"component_groups": [
"fly"
]
},
"remove": {
"component_groups": [
"walk"
]
}
}
"walk": {
"remove": {
"component_groups": [
"fly"
]
},
"add": {
"component_groups": [
"walk"
]
}
}Function : this code is for adding and removing component groups
When dismounted in the air, the pig would fall and take damage. To prevent this, we use minecraft:damage_sensor to ignore fall damage.
Defined under component_groups.minecraft:pig_saddled — Line ~212:
"minecraft:damage_sensor": {
"triggers": {
"cause": "fall",
"deals_damage": "no"
}
}When player ride the pig:
- Gravity is removed (via
flyevent) when player ride pig walkcomponent group is removedflycomponent group is added (disabling gravity)
When player dismounts the pig:
- Gravity is restored (via
walkevent) when player exit riding pig flycomponent group is removedwalkcomponent group is re-added
This enables air control using minecraft:input_air_controlled