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

TraceRays - finding the floor from a position


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
labelmaker
Member
Join Date: Mar 2009
Location: Kentucky USA
Old 04-04-2009 , 06:50   TraceRays - finding the floor from a position
Reply With Quote #1

I stayed up all night figuring this one out. Just how do you find the floor from a position. Well Ive got your answer.

As you can see angles are not x,y,z. Its actually pitch,yaw,roll
PHP Code:
new Float:pos[3];
new 
Float:floor[3];
new 
Float:ceiling[3];
new 
Float:direction[3];
new 
Handle:trace;
new 
Float:totalHeight;

for(new 
011; ++i)
{
    
pos[0] = GetRandomFloat(MapX[0],MapX[1]);
    
pos[1] = GetRandomFloat(MapY[0],MapY[1]);
    
pos[2] = GetRandomFloat(MapZ[0],MapZ[1]);
    
direction[0] = 89.0;//thats right you'd think its a z value - this will point you down
    
trace TR_TraceRayEx(posdirection,MASK_PLAYERSOLID_BRUSHONLYRayType_Infinite);
    if(
TR_DidHit(trace))
    {
        
TR_GetEndPosition(floortrace);
    }
    
direction[0] = -89.0;//this will point you up
    
trace TR_TraceRayEx(posdirection,MASK_PLAYERSOLID_BRUSHONLYRayType_Infinite);
    if(
TR_DidHit(trace))
    {
        
TR_GetEndPosition(ceilingtrace);
    }
    
//I find the height below to prevent players from becoming stuck
    
if (ceiling[2] < && floor[2] < 0)
    {
        
totalHeight FloatAbs(ceiling[2]) - FloatAbs(floor[2]);
    }
    else if (
ceiling[2] > && floor[2] > 0)
    {
        
totalHeight ceiling[2] - floor[2];
    }
    else
    {
        
totalHeight FloatAbs(ceiling[2]) + FloatAbs(floor[2]);
    }
    if (
FloatAbs(totalHeight) > 75.0)
    {
        
pos[2] = floor[2] + 20;//once again keep those players out of the dirt
        
11;
    }

__________________

Come Check Out the Popcorn Mod Yourself!!
labelmaker is offline
Send a message via Skype™ to labelmaker
 



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 18:13.


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