Ray trace hitting TEAM1 surface

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Ray trace hitting TEAM1 surface

Postby quartata » Mon Aug 01, 2016 3:40 pm

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?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Ray trace hitting TEAM1 surface

Postby iPlayer » Mon Aug 01, 2016 3:51 pm

Have you tried using ContentMasks.SOLID_BRUSH_ONLY as your mask?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Mon Aug 01, 2016 5:04 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Ray trace hitting TEAM1 surface

Postby L'In20Cible » Mon Aug 01, 2016 7:24 pm

Code?
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Mon Aug 01, 2016 8:54 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Ray trace hitting TEAM1 surface

Postby L'In20Cible » Tue Aug 02, 2016 12:09 am

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)
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Tue Aug 02, 2016 12:54 am

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.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Fri Aug 05, 2016 4:19 pm

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.
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: Ray trace hitting TEAM1 surface

Postby D3CEPTION » Fri Aug 05, 2016 7:52 pm

quartata wrote:But I don't understand why the surface mask doesn't seem to affect anything.


what exactly isnt working?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Ray trace hitting TEAM1 surface

Postby iPlayer » Fri Aug 05, 2016 8:53 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Fri Aug 05, 2016 11:43 pm

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)
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 12:52 am

How peculiar. Turns out it was the func_respawnroom (despite the fact that it's not solid)...
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 12:54 am

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)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Ray trace hitting TEAM1 surface

Postby Ayuto » Sat Aug 06, 2016 7:44 am

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
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 3:50 pm

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

Ayuto wrote: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


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).
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Ray trace hitting TEAM1 surface

Postby iPlayer » Sat Aug 06, 2016 4:00 pm

You can adapt is_in_solid to your needs: https://github.com/Source-Python-Dev-Te ... ty.py#L488
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 4:02 pm

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:

Image

All the traces go through the crack between the logs, so the function thinks there's no where I can move without falling.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 4:03 pm

iPlayer wrote:You can adapt is_in_solid to your needs: https://github.com/Source-Python-Dev-Te ... ty.py#L488


Ooh, I didn't know about those last two arguments to the Ray constructor. What do they do?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Ray trace hitting TEAM1 surface

Postby Ayuto » Sat Aug 06, 2016 4:11 pm

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.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: Ray trace hitting TEAM1 surface

Postby quartata » Sat Aug 06, 2016 4:14 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 110 guests