Вопрос Проблема с wish dir, wall angle, forwardmove, sidemove

Тьомчик
Участник
Статус
Оффлайн
Регистрация
30 Июн 2020
Сообщения
717
Реакции[?]
150
Поинты[?]
58K
Я не знаю как с калькулировать правильно wish dir и wall angle

function:
__forceinline float align_normalize_yaw(float f) {
    while (f < -180.0f)
        f += 360.0f;

    while (f > 180.0f)
        f -= 360.0f;

    return f;
}

void features::movement::auto_align(c_usercmd* cmd) {
    enum e_directions {
        e_forwards = 0,
        e_forwards_left = 45,
        e_forwards_right = -45,
        e_left = 90,
        e_right = -90,
        e_backwards_left = 135,
        e_backwards_right = -135,
        e_backwards = 180,
    };

    if (!c::movement::auto_align::enable)
        return;

    if (!interfaces::engine->is_in_game() || !interfaces::engine->is_connected())
        return;

    if (!g::local || !g::local->is_alive())
        return;

    if (g::local->move_type() == movetype_noclip || g::local->move_type() == movetype_ladder || g::local->move_type() == movetype_observer)
        return;

    if (g::local->flags() & fl_onground)
        return;

    if (!cmd)
        return;

    if (cmd->buttons & in_speed)
        cmd->buttons &= ~in_speed;

    float wish_direction = 0.0f;
  
    if (cmd->buttons & in_forward) {
        if (cmd->buttons & in_left)
            wish_direction += e_forwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_forwards_right;
        else
            wish_direction += e_forwards;
    }
    else if (cmd->buttons & in_back) {
        if (cmd->buttons & in_left)
            wish_direction += e_backwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_backwards_right;
        else
            wish_direction += e_backwards;
    }
    else if (cmd->buttons & in_left)
        wish_direction += e_left;
    else if (cmd->buttons & in_right)
        wish_direction += e_right;

    vec3_t view_angles = vec3_t(0.0f, 0.0f, 0.0f);
    interfaces::engine->get_view_angles(view_angles);

    vec3_t absolute_wish_angles = vec3_t(view_angles.x, view_angles.y + align_normalize_yaw(wish_direction), view_angles.z);

    vec3_t start = g::local->get_absolute_origin();
    vec3_t end = start /* + wish direction to our wall */;

    trace_filter filter;
    filter.skip = g::local;
  
    /* verify wall */

    trace_t detection_wall;
    ray_t detection_wall_ray;
    detection_wall_ray.initialize(start, end);

    interfaces::trace_ray->trace_ray(detection_wall_ray, MASK_PLAYERSOLID, &filter, &detection_wall);
    if (detection_wall.flFraction < 1.0f && detection_wall.plane.normal.z == 0.0f) {
        vec3_t adjusted = start /* + wall angle */;

        /* verify our feet on ideal angle for hug */

        trace_t new_detection_wall;
        ray_t new_detection_wall_ray;
        new_detection_wall_ray.initialize(start, adjusted);

        interfaces::trace_ray->trace_ray(new_detection_wall_ray, MASK_PLAYERSOLID, &filter, &new_detection_wall);

        /* if our angle not ideal we create a move's to be ideal */
        if (detection_wall.plane != new_detection_wall.plane) {

        }
    }
}
Пожалуйста, авторизуйтесь для просмотра ссылки.
Пожалуйста, авторизуйтесь для просмотра ссылки.
№1:
vec3_t to_wall = angles.to_angle();
to_wall.normalize();
vec3_t velo = g::local->velocity();
velo.z = 0.f;

if (velo.length_2d() > 0.f) {
    vec3_t velo_ang = velo.to_angle();
    vec3_t delta = velo_ang - to_wall;
    delta.normalize();
               
    if (fabsf(delta.z) > 90.f)
        break;
}

float rotation = math::deg2rad(to_wall.y - cmd->view_angles.y);
float cos_rot = cos(rotation);
float sin_rot = sin(rotation);
№2:
           Vector to_wall = Angles.toAngle();
            float mVel = hypotf(localPlayer->velocity().x, localPlayer->velocity().y);
            float ideal = radiansToDegrees(atanf(28.33f / mVel));
            Vector dvelo = localPlayer->velocity();
            dvelo.z = 0.f;
            Vector velo_angle = dvelo.toAngle();
            Vector delta = velo_angle - to_wall;
            delta.normalize();
            if (delta.y >= 0.f)
                to_wall.y += ideal;
            else
                to_wall.y -= ideal;
            float rotation = degreesToRadians(to_wall.y - cmd->viewangles.y);
            float cos_rot = cos(rotation);
            float sin_rot = sin(rotation);

            float forwardmove = cos_rot * 450.f;
            float sidemove = -sin_rot * 450.f;
 
Последнее редактирование:
Новичок
Статус
Оффлайн
Регистрация
6 Дек 2021
Сообщения
2
Реакции[?]
1
Поинты[?]
1K
Я не знаю как с калькулировать правильно wish dir и wall angle

function:
__forceinline float align_normalize_yaw(float f) {
    while (f < -180.0f)
        f += 360.0f;

    while (f > 180.0f)
        f -= 360.0f;

    return f;
}

void features::movement::auto_align(c_usercmd* cmd) {
    enum e_directions {
        e_forwards = 0,
        e_forwards_left = 45,
        e_forwards_right = -45,
        e_left = 90,
        e_right = -90,
        e_backwards_left = 135,
        e_backwards_right = -135,
        e_backwards = 180,
    };

    if (!c::movement::auto_align::enable)
        return;

    if (!interfaces::engine->is_in_game() || !interfaces::engine->is_connected())
        return;

    if (!g::local || !g::local->is_alive())
        return;

    if (g::local->move_type() == movetype_noclip || g::local->move_type() == movetype_ladder || g::local->move_type() == movetype_observer)
        return;

    if (g::local->flags() & fl_onground)
        return;

    if (!cmd)
        return;

    if (cmd->buttons & in_speed)
        cmd->buttons &= ~in_speed;

    float wish_direction = 0.0f;
 
    if (cmd->buttons & in_forward) {
        if (cmd->buttons & in_left)
            wish_direction += e_forwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_forwards_right;
        else
            wish_direction += e_forwards;
    }
    else if (cmd->buttons & in_back) {
        if (cmd->buttons & in_left)
            wish_direction += e_backwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_backwards_right;
        else
            wish_direction += e_backwards;
    }
    else if (cmd->buttons & in_left)
        wish_direction += e_left;
    else if (cmd->buttons & in_right)
        wish_direction += e_right;

    vec3_t view_angles = vec3_t(0.0f, 0.0f, 0.0f);
    interfaces::engine->get_view_angles(view_angles);

    vec3_t absolute_wish_angles = vec3_t(view_angles.x, view_angles.y + align_normalize_yaw(wish_direction), view_angles.z);

    vec3_t start = g::local->get_absolute_origin();
    vec3_t end = start /* + wish direction to our wall */;

    trace_filter filter;
    filter.skip = g::local;
 
    /* verify wall */

    trace_t detection_wall;
    ray_t detection_wall_ray;
    detection_wall_ray.initialize(start, end);

    interfaces::trace_ray->trace_ray(detection_wall_ray, MASK_PLAYERSOLID, &filter, &detection_wall);
    if (detection_wall.flFraction < 1.0f && detection_wall.plane.normal.z == 0.0f) {
        vec3_t adjusted = start /* + wall angle */;

        /* verify our feet on ideal angle for hug */

        trace_t new_detection_wall;
        ray_t new_detection_wall_ray;
        new_detection_wall_ray.initialize(start, adjusted);

        interfaces::trace_ray->trace_ray(new_detection_wall_ray, MASK_PLAYERSOLID, &filter, &new_detection_wall);

        /* if our angle not ideal we create a move's to be ideal */
        if (detection_wall.plane != new_detection_wall.plane) {

        }
    }
}
Пожалуйста, авторизуйтесь для просмотра ссылки.
Пожалуйста, авторизуйтесь для просмотра ссылки.
№1:
vec3_t to_wall = angles.to_angle();
to_wall.normalize();
vec3_t velo = g::local->velocity();
velo.z = 0.f;

if (velo.length_2d() > 0.f) {
    vec3_t velo_ang = velo.to_angle();
    vec3_t delta = velo_ang - to_wall;
    delta.normalize();
              
    if (fabsf(delta.z) > 90.f)
        break;
}

float rotation = math::deg2rad(to_wall.y - cmd->view_angles.y);
float cos_rot = cos(rotation);
float sin_rot = sin(rotation);
№2:
           Vector to_wall = Angles.toAngle();
            float mVel = hypotf(localPlayer->velocity().x, localPlayer->velocity().y);
            float ideal = radiansToDegrees(atanf(28.33f / mVel));
            Vector dvelo = localPlayer->velocity();
            dvelo.z = 0.f;
            Vector velo_angle = dvelo.toAngle();
            Vector delta = velo_angle - to_wall;
            delta.normalize();
            if (delta.y >= 0.f)
                to_wall.y += ideal;
            else
                to_wall.y -= ideal;
            float rotation = degreesToRadians(to_wall.y - cmd->viewangles.y);
            float cos_rot = cos(rotation);
            float sin_rot = sin(rotation);

            float forwardmove = cos_rot * 450.f;
            float sidemove = -sin_rot * 450.f;
Код:
void features::movement::auto_align(c_usercmd* cmd) {
    enum e_directions {
        e_forwards = 0,
        e_forwards_left = 45,
        e_forwards_right = -45,
        e_left = 90,
        e_right = -90,
        e_backwards_left = 135,
        e_backwards_right = -135,
        e_backwards = 180,
    };

    if (!c::movement::auto_align::enable)
        return;

    if (!interfaces::engine->is_in_game() || !interfaces::engine->is_connected())
        return;

    if (!g::local || !g::local->is_alive())
        return;

    if (g::local->move_type() == movetype_noclip || g::local->move_type() == movetype_ladder || g::local->move_type() == movetype_observer)
        return;

    if (g::local->flags() & fl_onground)
        return;

    if (!cmd)
        return;

    if (cmd->buttons & in_speed)
        cmd->buttons &= ~in_speed;

    float wish_direction = 0.0f;

    if (cmd->buttons & in_forward) {
        if (cmd->buttons & in_left)
            wish_direction += e_forwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_forwards_right;
        else
            wish_direction += e_forwards;
    }
    else if (cmd->buttons & in_back) {
        if (cmd->buttons & in_left)
            wish_direction += e_backwards_left;
        else if (cmd->buttons & in_right)
            wish_direction += e_backwards_right;
        else
            wish_direction += e_backwards;
    }
    else if (cmd->buttons & in_left)
        wish_direction += e_left;
    else if (cmd->buttons & in_right)
        wish_direction += e_right;

    vec3_t view_angles = vec3_t(0.0f, 0.0f, 0.0f);
    interfaces::engine->get_view_angles(view_angles);

    vec3_t absolute_wish_angles = vec3_t(view_angles.x, view_angles.y + align_normalize_yaw(wish_direction), view_angles.z);

    vec3_t start = g::local->get_absolute_origin();

    vec3_t end = start + (vec3_t(0, 0, 0) - start).normalize() * 50.0f;

    trace_filter filter;
    filter.skip = g::local;

    trace_t detection_wall;
    ray_t detection_wall_ray;
    detection_wall_ray.initialize(start, end);

    interfaces::trace_ray->trace_ray(detection_wall_ray, MASK_PLAYERSOLID, &filter, &detection_wall);

    if (detection_wall.flFraction < 1.0f && detection_wall.plane.normal.z == 0.0f) {

        vec3_t wall_angle = detection_wall.plane.normal.angle();

        vec3_t adjusted = start + (wall_angle * 5.0f);

        trace_t new_detection_wall;
        ray_t new_detection_wall_ray;
        new_detection_wall_ray.initialize(start, adjusted);

        interfaces::trace_ray->trace_ray(new_detection_wall_ray, MASK_PLAYERSOLID, &filter, &new_detection_wall);

        if (detection_wall.plane != new_detection_wall.plane) {
          
        }
    }
}
 
Сверху Снизу