Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float antiaim::best_head_position( ) {
- //getting the local player
- i_client_entity* local = interfaces::entity_list->get_client_entity( interfaces::engine->get_local_player() );
- //getting our current view angles
- vec3_t viewangle;
- interfaces::engine->get_view_angles( viewangle );
- // lambda function that gets the closest target by fov
- auto get_target_entity = [&]( void ) {
- // values that we use to compare the entities
- float best_fov = 360.0f;
- int best_target = -1;
- // iterate through the entity_list
- for (int i = 1; i <= interfaces::global_vars->max_clients; i++) {
- // find entity
- i_client_entity* entity = interfaces::entity_list->get_client_entity( i );
- // entity is not nullptr, not a team mate, not dormant and is alive
- if (!entity || !entity->sanity_checks( local, true ))
- continue;
- // get that fov
- float fov_to_entity = math::get_fov( viewangle, math::calc_angle( local->eye_pos(), entity->eye_pos() ) );
- // some comparisons
- if (fov_to_entity < best_fov) {
- best_fov = fov_to_entity;
- best_target = i;
- }
- }
- // ok now we have our entity
- return interfaces::entity_list->get_client_entity( best_target );
- };
- // we will require our eye positions
- vec3_t eye_position = local->eye_pos();
- // our results
- float yaw = -1.0f, highest_thickness = 0.0f;
- // if there is an entity
- i_client_entity* entity = get_target_entity();
- if (!entity) return yaw;
- // lambda function that will return the thicknes of the wall from a calculated head position
- auto check_wall_thickness = [&]( i_client_entity* entity, vec3_t position ) -> float {
- // getting the eye position of the entity we are targetting
- vec3_t entity_eye_position = entity->eye_pos();
- // we will use these as final measurements
- vec3_t endpos1, endpos2;
- // casting a ray from our calculated head position to the entities eye position
- ray_t ray;
- ray.init( position, entity_eye_position );
- // we dont want to come into contact with the entity or our selves
- c_trace_filter_skip_two_entities filter( entity, local );
- // tracing a ray using the parameters above
- trace_t trace1;
- interfaces::trace->trace_ray( ray, trace_mask::mask_shot_brushonly, &filter, &trace1 );
- // if the trace did hit something
- if (trace1.did_hit())
- endpos1 = trace1.m_endpos;
- else //or if we didnt
- return 0.f;
- // casting another ray that goes from the entity eye position to our calculated head position
- ray.init( entity_eye_position, position );
- // tracing a ray using the parameters above
- trace_t trace2;
- interfaces::trace->trace_ray( ray, trace_mask::mask_shot_brushonly, &filter, &trace2 );
- // if the trace did hit something
- if (trace2.did_hit())
- endpos2 = trace2.m_endpos;
- // final calculations to determine how thick the object was we just traced through
- float add = position.distance( entity_eye_position ) - eye_position.distance( entity_eye_position ) + 3.f;
- return endpos1.distance( endpos2 ) + add / 3;
- };
- // we will require our head positions
- vec3_t head_position = local->get_hitbox_position( hitboxes::hitbox_head );
- // we will require our abs origin
- vec3_t local_abs_origin = local->abs_origin();
- // the distance between our head and our abs origin
- float radius = fabs( vec3_t( head_position - local_abs_origin ).length_2d() );
- // this will result in a 45.0f deg step
- float angle_step = static_cast<float>(M_PI) / 4.0f;
- // iterate through 45.0f deg angles
- for (float n = 0.0f; n < (static_cast<float>(M_PI) * 2.0f) - angle_step; n += angle_step) {
- // creating a calculated head position
- vec3_t head_position( radius * cos( n ) + eye_position.x, radius* sin( n ) + eye_position.y, eye_position.z );
- // checking the thickness of the wall to the entity from the calculated head position
- float wall_thickness = check_wall_thickness( entity, head_position );;
- // if this wall is thicker than the previous walls then
- if (wall_thickness > highest_thickness){
- // set the thickest wall to this one
- highest_thickness = wall_thickness;
- // determine our optimal yaw
- yaw = n;
- }
- }
- //whoop whoop p freestanding
- return math::rad_to_deg( yaw );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement