Jump to content

source Movement Fix


xzasdSADDSADA
 Share

Recommended Posts

Can someone help me with a movement fix? sometimes it just randomly doesnt work

 

code below

 

    void MovementFix( CUserCmd* m_Cmd, QAngle wish_angle, QAngle old_angles ) {
        if( old_angles.pitch != wish_angle.pitch || old_angles.yaw != wish_angle.yaw || old_angles.roll != wish_angle.roll ) {
            Vector wish_forward, wish_right, wish_up, cmd_forward, cmd_right, cmd_up;

            auto viewangles = old_angles;
            auto movedata = Vector( m_Cmd->forwardmove, m_Cmd->sidemove, m_Cmd->upmove );
            viewangles.Normalize( );

            if( !( g_LocalPlayer->m_fFlags( ) & FL_ONGROUND ) && viewangles.roll != 0.f )
                movedata.y = 0.f;

            AngleVectors( wish_angle, wish_forward, wish_right, wish_up );
            AngleVectors( viewangles, cmd_forward, cmd_right, cmd_up );

            auto v8 = sqrt( wish_forward.x * wish_forward.x + wish_forward.y * wish_forward.y ), v10 = sqrt( wish_right.x * wish_right.x + wish_right.y * wish_right.y ), v12 = sqrt( wish_up.z * wish_up.z );

            Vector wish_forward_norm( 1.0f / v8 * wish_forward.x, 1.0f / v8 * wish_forward.y, 0.f ),
                wish_right_norm( 1.0f / v10 * wish_right.x, 1.0f / v10 * wish_right.y, 0.f ),
                wish_up_norm( 0.f, 0.f, 1.0f / v12 * wish_up.z );

            auto v14 = sqrt( cmd_forward.x * cmd_forward.x + cmd_forward.y * cmd_forward.y ), v16 = sqrt( cmd_right.x * cmd_right.x + cmd_right.y * cmd_right.y ), v18 = sqrt( cmd_up.z * cmd_up.z );

            Vector cmd_forward_norm( 1.0f / v14 * cmd_forward.x, 1.0f / v14 * cmd_forward.y, 1.0f / v14 * 0.0f ),
                cmd_right_norm( 1.0f / v16 * cmd_right.x, 1.0f / v16 * cmd_right.y, 1.0f / v16 * 0.0f ),
                cmd_up_norm( 0.f, 0.f, 1.0f / v18 * cmd_up.z );

            auto v22 = wish_forward_norm.x * movedata.x, v26 = wish_forward_norm.y * movedata.x, v28 = wish_forward_norm.z * movedata.x, v24 = wish_right_norm.x * movedata.y, v23 = wish_right_norm.y * movedata.y, v25 = wish_right_norm.z * movedata.y, v30 = wish_up_norm.x * movedata.z, v27 = wish_up_norm.z * movedata.z, v29 = wish_up_norm.y * movedata.z;

            Vector correct_movement;
            correct_movement.x = cmd_forward_norm.x * v24 + cmd_forward_norm.y * v23 + cmd_forward_norm.z * v25 + ( cmd_forward_norm.x * v22 + cmd_forward_norm.y * v26 + cmd_forward_norm.z * v28 ) + ( cmd_forward_norm.y * v30 + cmd_forward_norm.x * v29 + cmd_forward_norm.z * v27 );
            correct_movement.y = cmd_right_norm.x * v24 + cmd_right_norm.y * v23 + cmd_right_norm.z * v25 + ( cmd_right_norm.x * v22 + cmd_right_norm.y * v26 + cmd_right_norm.z * v28 ) + ( cmd_right_norm.x * v29 + cmd_right_norm.y * v30 + cmd_right_norm.z * v27 );
            correct_movement.z = cmd_up_norm.x * v23 + cmd_up_norm.y * v24 + cmd_up_norm.z * v25 + ( cmd_up_norm.x * v26 + cmd_up_norm.y * v22 + cmd_up_norm.z * v28 ) + ( cmd_up_norm.x * v30 + cmd_up_norm.y * v29 + cmd_up_norm.z * v27 );

            correct_movement.x = std::clamp( correct_movement.x, -450.f, 450.f );
            correct_movement.y = std::clamp( correct_movement.y, -450.f, 450.f );
            correct_movement.z = std::clamp( correct_movement.z, -320.f, 320.f );

            m_Cmd->forwardmove = correct_movement.x;
            m_Cmd->sidemove = correct_movement.y;
            m_Cmd->upmove = correct_movement.z;

            m_Cmd->buttons &= ~( IN_MOVERIGHT | IN_MOVELEFT | IN_BACK | IN_FORWARD );
            if( m_Cmd->sidemove != 0.0 ) {
                if( m_Cmd->sidemove <= 0.0 )
                    m_Cmd->buttons |= IN_MOVELEFT;
                else
                    m_Cmd->buttons |= IN_MOVERIGHT;
            }

            if( m_Cmd->forwardmove != 0.0 ) {
                if( m_Cmd->forwardmove <= 0.0 )
                    m_Cmd->buttons |= IN_BACK;
                else
                    m_Cmd->buttons |= IN_FORWARD;
            }
        }
    }

Link to comment
Share on other sites

void movement_fix(Vector& wish_angle, CUserCmd* m_pcmd)
    {
        Vector Zero(0.0f, 0.0f, 0.0f);

        Vector wish_forward, wish_right, wish_up, cmd_forward, cmd_right, cmd_up;

        auto viewangles = m_pcmd->m_viewangles;
        auto movedata = Vector(m_pcmd->m_forwardmove, m_pcmd->m_sidemove, m_pcmd->m_upmove);
        viewangles.Normalize();

        if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND) && viewangles.z != 0.f)
            movedata.y = 0.f;

        math::angle_vectors(wish_angle, &wish_forward, &wish_right, &wish_up);
        math::angle_vectors(viewangles, &cmd_forward, &cmd_right, &cmd_up);

        const auto v8 = sqrtf(wish_forward.x * wish_forward.x + wish_forward.y * wish_forward.y),
            v10 = sqrtf(wish_right.x * wish_right.x + wish_right.y * wish_right.y),
            v12 = sqrtf(wish_up.z * wish_up.z);

        Vector wish_forward_norm(1.0f / v8 * wish_forward.x, 1.0f / v8 * wish_forward.y, 0.f),
            wish_right_norm(1.0f / v10 * wish_right.x, 1.0f / v10 * wish_right.y, 0.f),
            wish_up_norm(0.f, 0.f, 1.0f / v12 * wish_up.z);

        const auto v14 = sqrtf(cmd_forward.x * cmd_forward.x + cmd_forward.y * cmd_forward.y),
            v16 = sqrtf(cmd_right.x * cmd_right.x + cmd_right.y * cmd_right.y),
            v18 = sqrtf(cmd_up.z * cmd_up.z);

        Vector cmd_forward_norm(1.0f / v14 * cmd_forward.x, 1.0f / v14 * cmd_forward.y, 1.0f / v14 * 0.0f),
            cmd_right_norm(1.0f / v16 * cmd_right.x, 1.0f / v16 * cmd_right.y, 1.0f / v16 * 0.0f),
            cmd_up_norm(0.f, 0.f, 1.0f / v18 * cmd_up.z);

        const auto v22 = wish_forward_norm.x * movedata.x,
            v26 = wish_forward_norm.y * movedata.x,
            v28 = wish_forward_norm.z * movedata.x,
            v24 = wish_right_norm.x * movedata.y,
            v23 = wish_right_norm.y * movedata.y,
            v25 = wish_right_norm.z * movedata.y,
            v30 = wish_up_norm.x * movedata.z,
            v27 = wish_up_norm.z * movedata.z,
            v29 = wish_up_norm.y * movedata.z;

        Vector correct_movement = Zero;

        correct_movement.x = cmd_forward_norm.x * v24 + cmd_forward_norm.y * v23 + cmd_forward_norm.z * v25
            + (cmd_forward_norm.x * v22 + cmd_forward_norm.y * v26 + cmd_forward_norm.z * v28)
            + (cmd_forward_norm.y * v30 + cmd_forward_norm.x * v29 + cmd_forward_norm.z * v27);

        correct_movement.y = cmd_right_norm.x * v24 + cmd_right_norm.y * v23 + cmd_right_norm.z * v25
            + (cmd_right_norm.x * v22 + cmd_right_norm.y * v26 + cmd_right_norm.z * v28)
            + (cmd_right_norm.x * v29 + cmd_right_norm.y * v30 + cmd_right_norm.z * v27);

        correct_movement.z = cmd_up_norm.x * v23 + cmd_up_norm.y * v24 + cmd_up_norm.z * v25
            + (cmd_up_norm.x * v26 + cmd_up_norm.y * v22 + cmd_up_norm.z * v28)
            + (cmd_up_norm.x * v30 + cmd_up_norm.y * v29 + cmd_up_norm.z * v27);

        correct_movement.x = math::clamp(correct_movement.x, -450.f, 450.f);
        correct_movement.y = math::clamp(correct_movement.y, -450.f, 450.f);
        correct_movement.z = math::clamp(correct_movement.z, -320.f, 320.f);

        m_pcmd->m_forwardmove = correct_movement.x;
        m_pcmd->m_sidemove = correct_movement.y;
        m_pcmd->m_upmove = correct_movement.z;
    }

have you tried this one? public code^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...