Raised This Month: $ Target: $400
 0% 

Set origin entity to ground


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
McTavish
Senior Member
Join Date: May 2021
Old 01-11-2023 , 13:32   Re: Set origin entity to ground
Reply With Quote #5

Quote:
Originally Posted by RayZek95 View Post
And without that? I need to know what I'm doing, the way using vectors like the stock I posted
I'm a noob at scripting but I can help I guess.

Code:
stock GetUserEyePosition(iId, Float:vecReturn[3], Float:fNormalDist)
{
    static Float:vecStart[3], Float:vecEnd[3]
    entity_get_vector(iId, EV_VEC_origin, vecStart)
    entity_get_vector(iId, EV_VEC_view_ofs, vecEnd)

    xs_vec_add(vecStart, vecEnd, vecEnd)

    entity_get_vector(iId, EV_VEC_v_angle, vecEnd)
    engfunc(EngFunc_MakeVectors, vecEnd)
    get_global_vector(GL_v_forward, vecEnd)
    xs_vec_mul_scalar(vecEnd, 9999.9, vecEnd)

    xs_vec_add(vecStart, vecEnd, vecEnd)

    engfunc(EngFunc_TraceLine, vecStart, vecEnd, DONT_IGNORE_MONSTERS, iId, 0)

    // Check if the trace hit the ground
    if(get_tr2(0, TR_iHitgroup) == HITGROUP_GENERIC && get_tr2(0, TR_flFraction) < 1.0)
    {
        // Check if the trace hit the floor 
        if(get_tr2(0, TR_iHitgroup) & CONTENTS_SOLID)
        {
            // Get the trace end position
            get_tr2(0, TR_vecEndPos, vecReturn)

            // Set the origin of the entity to the trace end position with Z = 0
            vecReturn[2] = 0.0
            entity_set_vector(iId, EV_VEC_origin, vecReturn)
        }
    }
}
This function works by first checking if the trace hit the ground using the get_tr2(0, TR_iHitgroup) function, and the fraction of the trace using the get_tr2(0, TR_flFraction) function. If the trace hit the ground and the fraction is less than 1, it will check if the trace hit the floor using the get_tr2(0, TR_iHitgroup) & CONTENTS_SOLID where the CONTENTS_SOLID macro is a flag that represents the floor or solid ground. If the trace hit the floor, it will set the origin of the entity to the trace end position with Z = 0 using the entity_set_vector(iId, EV_VEC_origin, vecReturn) function.
__________________
No Steam = No Support.
McTavish is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode