AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set origin entity to ground (https://forums.alliedmods.net/showthread.php?t=341220)

RayZek95 01-10-2023 20:42

Set origin entity to ground
 
Hi everyone, there's a way to set the origin of an entity to ground?

I tried this way of metalicross:
PHP Code:

stock GetUserEyePosition(iIdFloat:vecReturn[3], Float:fNormalDist// mia gordo mia :3
{
    static 
Float:vecStart[3], Float:vecEnd[3]
    
entity_get_vector(iIdEV_VEC_originvecStart)
    
entity_get_vector(iIdEV_VEC_view_ofsvecEnd)
    
    
xs_vec_add(vecStartvecEndvecEnd// vista de los ojos
    
    
entity_get_vector(iIdEV_VEC_v_anglevecEnd)
    
engfunc(EngFunc_MakeVectorsvecEnd)
    
get_global_vector(GL_v_forwardvecEnd)
    
xs_vec_mul_scalar(vecEnd9999.9vecEnd)
    
    
xs_vec_add(vecStartvecEndvecEnd// vista a la mierda de los ojos
    
    
engfunc(EngFunc_TraceLinevecStartvecEndDONT_IGNORE_MONSTERSiId0)
    
    
get_tr2(0TR_vecPlaneNormalvecEnd)
    
xs_vec_mul_scalar(vecEndfNormalDistvecEnd// distancia de la normal de la superficie
    
    
get_tr2(0TR_vecEndPosvecReturn)
    
xs_vec_add(vecReturnvecEndvecReturn)


Works, but I want to restrict that for only aiming the ground; and in the case that is aiming the ground always set the origin in Z coordenate = 0 (in other words, "set to ground")

EFFx 01-10-2023 23:24

Re: Set origin entity to ground
 
https://www.amxmodx.org/api/engine/drop_to_floor

RayZek95 01-11-2023 00:22

Re: Set origin entity to ground
 
And without that? I need to know what I'm doing, the way using vectors like the stock I posted

EFFx 01-11-2023 00:39

Re: Set origin entity to ground
 
Doing more calculations to reach the same end result that a simple native call would do for you makes no sense, just follow the damn suggestion CJ.

HamletEagle 01-11-2023 07:19

Re: Set origin entity to ground
 
Quote:

Originally Posted by RayZek95 (Post 2796890)
And without that? I need to know what I'm doing, the way using vectors like the stock I posted

Read the notes to understand how the function works:
Quote:

This engine function traces 256 units straight downwards from the
entity origin. If the trace hits the floor, the origin is updated to
the end position of the trace, FL_ONGROUND is added to the flags and
EV_ENT_groundentity is updated. When the trace does not hit anything or
the entity would be stuck inside something, the function does nothing
and returns 0.

McTavish 01-11-2023 13:32

Re: Set origin entity to ground
 
Quote:

Originally Posted by RayZek95 (Post 2796890)
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.

RayZek95 01-12-2023 15:02

Re: Set origin entity to ground
 
I get it... thank you all. And thanks McTravish

shayan123 01-13-2023 12:01

Re: Set origin entity to ground
 
Yes, there is a way to set the origin of an entity to the ground. One way to do this is by using the TraceLine function to trace a line from the entity's current origin to a point below it (for example, the origin minus the entity's view offset) and then using the TraceEndPos output to set the entity's origin to the point where the trace hit the ground. This method is similar to the one you provided, but you can use the TraceEndPos output to set the origin of the entity.

Another way to do this is using a plugin like 'groundme' which is a plugin that can be used to change the origin of an entity to the point where it is on the ground.

You can also use the built in function 'engfunc(EngFunc_SetOrigin, ent, origin_vector)' where ent is the index of the entity and origin_vector is the new origin for the entity. This will change the origin of an entity to the specific origin that you provide.

You can also use the built-in function 'engfunc(EngFunc_DropToFloor,ent)' where ent is the index of the entity. this will set the origin of the entity to the point where it is on the ground.


All times are GMT -4. The time now is 10:30.

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