line from player to nearest ground

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

line from player to nearest ground

Post 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.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 .
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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 ))
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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 :(
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Uhm... presumably local.groundtarget is something that doesn't have an origin?
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 .
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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!
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 " ... "
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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? ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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 :)
}
}
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply