Page 1 of 1

line from player to nearest ground

Posted: Wed Mar 16, 2005 3:19 am
by lizardkid
what's the code for if a line (or func_beam) touches the ground?

i need a line from the player (NOT binocs) to the nearest brush/patch/LOD. i jsut dont know the code for detecting brushes with lines.

Posted: Wed Mar 16, 2005 10:28 am
by bdbodger
local.fwd_vec = angles_toforward local.player.viewangles
local.start = local.player gettagposition "Bip01 Head"

local.range = 10240

local.groundtarget.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0

like that you mean ? it does a trace and gives you the spot where the trace hits something . No line though at least not one you can see .

Posted: Wed Mar 16, 2005 5:31 pm
by Rookie One.pl
Bdbodger, your code does a trace from player's head to where's the player looking at, and I don't think that's what he asked for.

You can trace the func_beam endpoint that would go straight down to the ground like this:

Code: Select all

local.endpoint = trace local.player.origin (local.player.origin + ( 0 0 -16384 ))

Posted: Wed Mar 16, 2005 7:09 pm
by lizardkid
like that you mean ? it does a trace and gives you the spot where the trace hits something . No line though at least not one you can see .
exactly what i need. if it draws a trace to the nearest solid and get the position of the spot it hit the solid, it's what i want. from what i see of it that's what it does.

thanks BD!
Bdbodger, your code does a trace from player's head to where's the player looking at, and I don't think that's what he asked for.
that's useful as well, just showed me how to offset a trace downwards too, which was going to be my next question :D

Posted: Thu Mar 17, 2005 12:27 am
by bdbodger
Well anyway it does a trace from point A to point B and the result is the spot it hit if it hit anything at all . The 0 at the end tell it to not pass entites

trace( Vector start, Vector end, [ Integer pass_entities ], [ Vector mins ], [ Vector maxs ] )

Performs a Trace Line from the start to the end, returns the end or the position it hit at

not sure what the Vector mins or Vector maxs are used for

Posted: Sun Mar 20, 2005 1:05 am
by lizardkid
bad news, i just tried it after getting errors and deciding to skip them and work on other things, i just got back to it and apparently, the trace isn't getting anything at all.
local.fwd_vec = angles_toforward local.player.viewangles
local.start = local.player gettagposition "Bip01 Head"

local.range = 10240

local.groundtarget.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0
iprintln "origin is " local.groundtarget.origin " ... "
the iprintln always returns NIL... i tried it with .origin and without it. apparently the trace isn't working :(

Posted: Sun Mar 20, 2005 6:49 am
by jv_map
Uhm... presumably local.groundtarget is something that doesn't have an origin?

Posted: Sun Mar 20, 2005 12:05 pm
by bdbodger
local.groundtarget.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0
Yes local.groundtarget was a script_origin from my player spotlight script . Any time you use local.something.origin it has to be something to have an origin or for you to give it an origin dosen't it ! , if you take out the origin part it should give you a set of coords but then you have to make sure the coords do not match the endpoint because that means it did not hit anything .
local.ground = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0
if you do that then local.ground will be the coords it hit at or didn't hit at as the case maybe . If you use a very far endpoint it should hit something I guess .

Posted: Wed Apr 06, 2005 3:48 am
by lizardkid

Code: Select all

local.fwd_vec = angles_toforward local.player.viewangles 
local.start = local.player gettagposition "Bip01 Head" 
local.range = 10240 
local.ground = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0 
iprintln "origin is " local.ground " ... "

level.Private1 runto local.ground
level.Private2 runto local.ground
level.Private3 runto local.ground
level.Medic    runto local.ground
level.Sergeant runto local.ground
level.Heavy    runto local.ground
level.Captain  runto local.ground
and it without fail, when i invoke the commands, it says something about actor not being able to use moveto and the origin that i'm *hoping* to get with the trace, while staring at the ground, comes up NIL each time. without fail.

HELP!

Posted: Wed Apr 06, 2005 9:56 am
by bdbodger
Try putting some iprintln statements in there to see what is working . Did you define what local.player was ? If you are testing it alone try $player instead of local.player . If local.player and local.start are defined then there is no way that local.ground would display nil it would display coords .

local.fwd_vec = angles_toforward local.player.viewangles
iprintln local.fwd_vec
local.start = local.player gettagposition "Bip01 Head"
iprintln local.start
local.range = 10240
local.ground = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0
iprintln "origin is " local.ground " ... "

Posted: Wed Apr 06, 2005 2:04 pm
by Rookie One.pl
Actors can runto entities only. Spawn a script_origin there.

I see you're still working on that bot command mod, eh? ;)

Posted: Wed Apr 06, 2005 2:38 pm
by lizardkid
YES! that was it! i hadn't defined local.player as $player!
*dissolves into happy sobbing*
I see you're still working on that bot command mod, eh?
heh yeah... slowly making my way through it :)
but it's good experience.

ok now... you said it does entities too right? how can i tell what kind of entity it hits if it does? some kind of command,

Code: Select all

if(isEntity local.ground)
{
local.entity = parm.other
iprintln "You hit an entity!"
if(local.entity.classname == func_door || local.entity.classname == func_rotatingdoor)
{
// do something cool :)
}
}

Posted: Wed Apr 06, 2005 6:02 pm
by Rookie One.pl
Ah, sorry, I was wrong. Actors apparently can runto vectors.

As to your question, no. Local.ground is a variable of type vector, not entity.

There is no perfect way to determine if a thing on certain coords is or is not an entity, but if you really want it, you could perform a double trace - one with the pass_entities flag set to 1, and one with it set to 0.

Code: Select all

// let's assume local.ground is the spot
local.check_w_ents = trace (local.ground + ( 0 0 64 )) (local.ground + ( 0 0 -8 )) 0 // the last 0 is the pass_entities flag
local.check_wo_ents = trace (local.ground + ( 0 0 64 )) (local.ground + ( 0 0 -8 )) 1
if (local.check_w_ents != local.check_wo_ents)
   println "There's an entity between " local.check_w_ents " and " local.check_wo_ents "!"
Apparently, this method is not perfect because the entities have different heights and you cannot determine the exact position of the entity.