Page 1 of 2
Ray trace hitting TEAM1 surface
Posted: Mon Aug 01, 2016 3:40 pm
by quartata
Hello again.
I'm making a TF2 plugin and I'm trying to do a ray trace from the player's current position straight down that only hits brushes, but I keep hitting a surface at the player's position with a surface flag of TEAM1. I'm not quite sure what this flag is (looking it up told me that it has something to do with player-player collisions which makes sense since the trace starts inside the player), but it seems like no matter what I do my trace keeps hitting that surface. Even using a mask of
Code: Select all
0xFFFFFFFF & ~ContentFlags.TEAM1 & ~ContentFlags.TEAM2
doesn't work. What's going on?
Re: Ray trace hitting TEAM1 surface
Posted: Mon Aug 01, 2016 3:51 pm
by iPlayer
Have you tried using ContentMasks.SOLID_BRUSH_ONLY as your mask?
Re: Ray trace hitting TEAM1 surface
Posted: Mon Aug 01, 2016 5:04 pm
by quartata
iPlayer wrote:Have you tried using ContentMasks.SOLID_BRUSH_ONLY as your mask?
Yeah I tried it and PLAYER_SOLID_BRUSH_ONLY, they don't change anything.
Re: Ray trace hitting TEAM1 surface
Posted: Mon Aug 01, 2016 7:24 pm
by L'In20Cible
Code?
Re: Ray trace hitting TEAM1 surface
Posted: Mon Aug 01, 2016 8:54 pm
by quartata
Relevant snippet of it:
Syntax: Select all
directions = [
[8, Vector(16, 0, 0), 16], # forward
[1032, Vector(8, 8, 0), 11.314], # forward + right
[1024, Vector(0, 16, 0), 16], # right
[1040, Vector(-8, 8, 0), 11.314], # backwards + right
[16, Vector(-16, 0, 0), 16], # backwards
[528, Vector(-8, -8, 0), 11.314], # backwards + left
[512, Vector(0, -16, 0), 16], # left
[520, Vector(8, -8, 0), 11.314], # forward + left
]
ray_end = Vector(0, 0, -200)
...
def get_neighbors(current, explored, yaw):
for button, direction, cost in directions:
debug("direction" + str(button))
node = Vector(0, 0, 0)
node.mul_add(rotate(direction, m_radians(yaw)), current, 1.0)
debug(node)
if node in explored:
debug("branch 1")
result = explored[node]
if result: yield result, button, cost
else:
debug("branch 2")
trace = GameTrace()
end = Vector(0, 0, 0)
end.mul_add(node, ray_end, 1.0)
debug(end)
engine_trace.trace_ray(Ray(node, end), ContentMasks.SOLID_BRUSH_ONLY, TraceFilterSimple(trace_type=TraceType.WORLD_ONLY), trace)
if trace.did_hit():
result = trace.end_position
debug(result)
debug("Trace flags:" + str(trace.surface.flags))
if result != node or trace.surface.flags & ContentFlags.MOVEABLE:
explored[node] = result
yield result, button, cost
else:
explored[node] = 0
(mind the debug statements)
I should have clarified at the beginning: it isn't exactly the player's current position, however the ray is inside the player model.
Re: Ray trace hitting TEAM1 surface
Posted: Tue Aug 02, 2016 12:09 am
by L'In20Cible
What if you replace this:
Syntax: Select all
TraceFilterSimple(trace_type=TraceType.WORLD_ONLY)
With:
Syntax: Select all
TraceFilterSimple(ignore=[player.index for player in PlayerIter()], trace_type=TraceType.WORLD_ONLY)
Re: Ray trace hitting TEAM1 surface
Posted: Tue Aug 02, 2016 12:54 am
by quartata
L'In20Cible wrote:What if you replace this:
Syntax: Select all
TraceFilterSimple(trace_type=TraceType.WORLD_ONLY)
With:
Syntax: Select all
TraceFilterSimple(ignore=[player.index for player in PlayerIter()], trace_type=TraceType.WORLD_ONLY)
No change. I also tried earlier making my own trace filter that always returned False for should_hit_entity, no effect.
Re: Ray trace hitting TEAM1 surface
Posted: Fri Aug 05, 2016 4:19 pm
by quartata
Just to confirm, I extended TraceFilterSimple and added a print statement to should_hit_entity and it's never called. So it's definitely not an entity (which is good, that means that TraceType.WORLD_ONLY is doing what it's supposed to do). But I don't understand why the surface mask doesn't seem to affect anything.
Re: Ray trace hitting TEAM1 surface
Posted: Fri Aug 05, 2016 7:52 pm
by D3CEPTION
quartata wrote:But I don't understand why the surface mask doesn't seem to affect anything.
what exactly isnt working?
Re: Ray trace hitting TEAM1 surface
Posted: Fri Aug 05, 2016 8:53 pm
by iPlayer
what exactly isnt working?
no matter what I do my trace keeps hitting that surface
2quartata
My guess is that one of your offsetting vectors (
directions) makes the trace ray start from inside the floor or wall. What if you use noclip to stay absolutely in the air - does the ray still hit player position?
By the way, there's a lose connection between description of the idea in the first post and the code you've provided. Maybe you could describe the function and the reason you need to make those offsets? At least I didn't get it.
Re: Ray trace hitting TEAM1 surface
Posted: Fri Aug 05, 2016 11:43 pm
by quartata
iPlayer wrote:
By the way, there's a lose connection between description of the idea in the first post and the code you've provided. Maybe you could describe the function and the reason you need to make those offsets? At least I didn't get it.
The first post was kinda misleading, sorry. It's a helper function for pathfinding. For a given point, I want to do a ray trace for each offset to get all the positions that can be moved to from there in one usercmd. If the trace immediately stops (end of the trace == start of the ray), I know it's inside an obstacle. (It just so happens that the starting point is where the player is.)
iPlayer wrote:My guess is that one of your offsetting vectors (directions) makes the trace ray start from inside the floor or wall. What if you use noclip to stay absolutely in the air - does the ray still hit player position?
I'll try it, but I'm pretty sure it's from collision with the player model not a brush. (It could be from the func_respawnroom or something though)
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 12:52 am
by quartata
How peculiar. Turns out it was the func_respawnroom (despite the fact that it's not solid)...
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 12:54 am
by quartata
When outside of the func_respawnroom, the rays aren't hitting anything at all it seems when I'm on the ground, but in the air it's fine. The rays shouldn't be starting in the ground (or at least not all of them); the surface is completely flat and I'm starting from the origin of the player (which should be above the ground)
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 7:44 am
by Ayuto
If you want to know whether the player is in an obstacle, you can use this one:
http://wiki.sourcepython.com/developing ... s_in_solid
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 3:50 pm
by quartata
OK, so origin of the player entity != model origin. Oops :P Using the eye location makes it work, but even when I'm against a wall it still thinks I can move towards it since the 16 unit offset from the center isn't enough to make it stick inside the wall. I think ray tracing alone isn't quite the right tool...
If I could specify a point to check (rather than the entity's current origin) this would be perfect (I could use that to detect obstacles and ray tracing to detect the >200 HUs drops).
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 4:00 pm
by iPlayer
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 4:02 pm
by quartata
Hmm, I don't even think a simple ray trace would be good enough for detecting places where the player would fall and take damage. Take this spot on Snakewater mid:

All the traces go through the crack between the logs, so the function thinks there's no where I can move without falling.
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 4:03 pm
by quartata
Ooh, I didn't know about those last two arguments to the Ray constructor. What do they do?
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 4:11 pm
by Ayuto
quartata wrote:Ooh, I didn't know about those last two arguments to the Ray constructor. What do they do?
They create a box like trace. In this case the trace is the player's bounding box.
Re: Ray trace hitting TEAM1 surface
Posted: Sat Aug 06, 2016 4:14 pm
by quartata
Ayuto wrote:quartata wrote:Ooh, I didn't know about those last two arguments to the Ray constructor. What do they do?
They create a box like trace. In this case the trace is the player's bounding box.
Oh, well that helps a lot. I'll try that then.