feat: get-ground-distance function for player blackboard

This commit is contained in:
Sara Gerretsen 2026-05-14 15:18:41 +02:00
parent 3d21a81329
commit d1a810ce9d
2 changed files with 8 additions and 0 deletions

View file

@ -14,6 +14,7 @@ void PlayerBehaviourTree::_bind_methods() {
BIND_HPROPERTY(Variant::OBJECT, hang_ray, PROPERTY_HINT_NODE_TYPE, "RayCast3D", PROPERTY_USAGE_READ_ONLY);
BIND_HPROPERTY(Variant::OBJECT, ground_ray, PROPERTY_HINT_NODE_TYPE, "RayCast3D", PROPERTY_USAGE_READ_ONLY);
ClassDB::bind_method(D_METHOD("get_world_move_input"), &self_type::get_world_move_input);
ClassDB::bind_method(D_METHOD("get_ground_distance"), &self_type::get_ground_distance);
}
void PlayerBehaviourTree::_notification(int what) {
@ -60,3 +61,9 @@ Vector3 PlayerBehaviourTree::get_world_move_input() const {
forward.normalized() * this->move_input.y
};
}
float PlayerBehaviourTree::get_ground_distance() const {
return (this->ground_ray->is_colliding()
? this->ground_ray->get_collision_point().distance_to(this->ground_ray->get_global_position())
: Math::INF);
}

View file

@ -34,4 +34,5 @@ public:
GET_SET_FNS(Node3D *, character);
GET_SET_FNS(AnimationTree *, anim);
GET_SET_FNS(RayCast3D *, hang_ray);
float get_ground_distance() const;
};