Raised This Month: $51 Target: $400
 12% 

Set origin entity to ground


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RayZek95
Junior Member
Join Date: Sep 2013
Old 01-10-2023 , 20:42   Set origin entity to ground
Reply With Quote #1

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")
__________________
RayZek95 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-10-2023 , 23:24   Re: Set origin entity to ground
Reply With Quote #2

https://www.amxmodx.org/api/engine/drop_to_floor
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
RayZek95
Junior Member
Join Date: Sep 2013
Old 01-11-2023 , 00:22   Re: Set origin entity to ground
Reply With Quote #3

And without that? I need to know what I'm doing, the way using vectors like the stock I posted
__________________
RayZek95 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-11-2023 , 00:39   Re: Set origin entity to ground
Reply With Quote #4

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.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-11-2023 at 00:40.
EFFx is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-11-2023 , 07:19   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
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.
__________________

Last edited by HamletEagle; 01-11-2023 at 07:19.
HamletEagle is online now
McTavish
Senior Member
Join Date: May 2021
Old 01-11-2023 , 13:32   Re: Set origin entity to ground
Reply With Quote #6

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
RayZek95
Junior Member
Join Date: Sep 2013
Old 01-12-2023 , 15:02   Re: Set origin entity to ground
Reply With Quote #7

I get it... thank you all. And thanks McTravish
__________________
RayZek95 is offline
shayan123
BANNED
Join Date: Oct 2020
Location: GB
Old 01-13-2023 , 12:01   Re: Set origin entity to ground
Reply With Quote #8

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.
shayan123 is offline
Send a message via ICQ to shayan123 Send a message via AIM to shayan123 Send a message via Yahoo to shayan123 Send a message via Skype™ to shayan123
Reply



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 06:29.


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