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

Solved Spawn entity over the ground


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 10-08-2022 , 03:21   Spawn entity over the ground
Reply With Quote #1

Hi,

is there a way to detect the ground under an entity? I mean how far it is under it?

Like lets say you spawn an prop_dynamic entity in the air like say between 200-400 pixels over the ground.

And it should hover 100 pixel over it. How would you teleport it down according to the actual ground?

Another example, you spawn an entity in front of you and used the position of yourself but the ground in front of you is deeper or higher.

How would you know the needed height for the entity?

Atm I adjust the height with

vPos[2] -= 60;

Thats OK on plain terrain but not like when you stand on a rock or somthing like that. The entity spawn must be dynamic.

Thx in advance.
__________________

Last edited by finishlast; 10-09-2022 at 06:48.
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-08-2022 , 04:14   Re: Spawn entity over the ground
Reply With Quote #2

PHP Code:
float GetGroundHeight(float vPos[3])
{
    
float vAng[3];

    
Handle trace TR_TraceRayFilterEx(vPosview_as<float>({ 90.00.00.0 }), MASK_ALLRayType_InfiniteTraceEntityFilterPlayer);
    if( 
TR_DidHit(trace) )
        
TR_GetEndPosition(vAngtrace);

    
delete trace;
    return 
vAng[2];
}

// Taken from "[L4D2] Weapon/Zombie Spawner"
// By "Zuko & McFlurry"
bool SetTeleportEndPoint(int clientfloat vPos[3], float vAng[3])
{
    
float vAngles[3], vOrigin[3];

    
GetClientEyePosition(clientvOrigin);
    
GetClientEyeAngles(clientvAngles);

    
Handle trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);

    if( 
TR_DidHit(trace) )
    {
        
float vBuffer[3], vStart[3], distance;

        
TR_GetEndPosition(vStarttrace);
        
distance = -15.0;
        
GetAngleVectors(vAnglesvBufferNULL_VECTORNULL_VECTOR);
        
vPos[0] = vStart[0] + (vBuffer[0] * distance);
        
vPos[1] = vStart[1] + (vBuffer[1] * distance);
        
vPos[2] = vStart[2] + (vBuffer[2] * distance);
        
vPos[2] = GetGroundHeight(vPos);
        if( 
vPos[2] == 0.0 )
        {
            
delete trace;
            return 
false;
        }

        
vAng vAngles;
    }
    else
    {
        
delete trace;
        return 
false;
    }

    
delete trace;
    return 
true;

From various spawners of mine.
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 10-08-2022 , 07:03   Re: Spawn entity over the ground
Reply With Quote #3

Thank you silvers, I already looked into your scripts, it is all rocket science to me, that's why I hoped for a solution for dumb people like me

I put on my studdy glasses and this is working now, I don't know fully why it is working but well

Thank you again! And again.... And the other times too....
Attached Files
File Type: sp Get Plugin or Get Source (l4d_halloween_jumpscare.sp - 38 views - 9.8 KB)
__________________

Last edited by finishlast; 10-09-2022 at 11:30.
finishlast is offline
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 10:18.


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