AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   trace_line to the ground (https://forums.alliedmods.net/showthread.php?t=100477)

Bad_Bud 08-14-2009 22:48

trace_line to the ground
 
Hi, I've read a lot of posts that suggest tracing a line to the ground, but I've not seen one that shows the actual code for doing so.

Would I be allowed to just set the endpoint to 5000 below the starting point, or is there some optimal value I should set it to?

Also, I'm finding random spots above the ground. How do I know when my spot I've found is below the entire map?

What I have is fully functional, I just don't know if my methods are terrible or not.

ConnorMcLeod 08-15-2009 03:34

Re: trace_line to the ground
 
Please show some code, and tell why you do that.

Bad_Bud 08-15-2009 03:57

Re: trace_line to the ground
 
Not much to show. I have defined two points that create a large box in a map. Within this box, I wish to spawn things 50 units above the ground. Here's how I'm getting my points (this works):

PHP Code:

FindPointAboveGround(Float:Origin[3])
{
    static 
Float:Start[3]
    static 
Float:End[3]
    
    do
    {
        
Start[0]=random_float(X1,X2)
        
Start[1]=random_float(Y1,Y2)
        
Start[2]=random_float(Z1,Z2)
        
        
End[0]=Start[0]
        
End[1]=Start[1]
        
End[2]=(Start[2]-5000.0)
        
        
trace_line(0,Start,End,Origin)
    }while(
Origin[2]<-5000.0)
    
    
Origin[2]+=50.0


But I don't know if this is necessarily a "good way" to do it, by assigning an arbitrarily huge number to trace down to, or if there's another way to make it just trace until it hits the ground.

The Origin[2]<-5000.0 condition is what I check against to see if my random start point was created inside of a wall, in which case it traces through the map to the huge number below, and I do it again.

Arkshine 08-15-2009 04:02

Re: trace_line to the ground
 
I think you need just one trace. Start shoud be the same as End, and End[2] you remove 5000. Get the TR_flFraction of the trace, if <1.0, you have touched something, otherwise nothing.

Bad_Bud 08-15-2009 04:25

Re: trace_line to the ground
 
Heh, sorry, it's my first time working with trace_line. I couldn't find any good posts on it when searching for trace_line, but I found some good tutorials while looking for TR_flFraction. I should be okay now. ;)

Thanks.


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

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