Teleport a certain distance in players view direction without destination in wall
Posted: Mon May 11, 2020 4:09 pm
I am trying to make a player teleport for a certain distance in the direction of his view vector.
I came across this post https://forums.sourcepython.com/viewtopic.php?f=20&t=742&hilit=solid+trace where L'In20Cible had already provided what I think is what I am looking for:
Now since I would like to teleport for a certain distance it could happen that the coordinates of the destination are inside a wall or something. Basically what the code above does - checking if a player would be blocked. This is where I would need some explanation:
How does Ray() exactly work ? From the wiki(http://wiki.sourcepython.com/developing ... .trace.Ray) I can only tell that I can either provide 3 or 5 arguments and I am not sure what to pass as arguments.
Then for engine_trace.trace_ray() I could not find an entry in the wiki but in the source code (https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/engines/engines_trace_wrap.cpp) which tells me:
The parameter "ray" is the ray instance, that is clear. But I don't really understand what "mask", "filter" and trace does.
Overall my understanding is that I create a ray instance with starting point and end point that somewhat will be the size of a players model and then either move the model(not the actual model but the sizes of the players model) along the 'trace' and check if it hit anything (like a wall) or only check the endpoint for any wall collision. If somebody could explain to me how this trace_ray works to check if the destination point would get the player stuck, that would be great.
The ultimate goal for me then is to make the teleport work in a way like this:
If the destination point would get the player stuck then try a destination point a little closer (I don't know, a fixed step like the player models width) and check again if that destination point would get the player stuck. Repeat that until a destination point will be valid and then teleport the player to those coordinates
I came across this post https://forums.sourcepython.com/viewtopic.php?f=20&t=742&hilit=solid+trace where L'In20Cible had already provided what I think is what I am looking for:
L'In20Cible wrote:I checked the history and it was not working cause you omitted the player's mins/maxs. Taking the code I linked to you, a little modification should do the trick:Now you can simply do something like:Syntax: Select all
# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python
# Engines
from engines.trace import ContentMasks
from engines.trace import engine_trace
from engines.trace import GameTrace
from engines.trace import Ray
from engines.trace import TraceFilterSimple
# Filters
from filters.players import PlayerIter
# Players
from players.helpers import playerinfo_from_index
# ============================================================================
# >> HELPER FUNCTIONS
# ============================================================================
def will_player_stuck(player_index, location):
'''Return whether or not the given player will stuck ay yhr given
location.'''
# Get the player's PlayerInfo instance...
player_info = playerinfo_from_index(player_index)
# Get a Ray object based on the player physic box...
ray = Ray(location, location, player_info.get_player_mins(),
player_info.get_player_maxs())
# Get a new GameTrace instance...
trace = GameTrace()
# Do the trace...
engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, TraceFilterSimple(), trace)
# Return whether or not the trace did hit...
return trace.did_hit()Syntax: Select all
def teleport_to_spawnpoint(player_index):
# Loop through all spawnpoints...
for spawnpoint in spawnpoints:
# Will the player stuck there?
if will_player_stuck(player_index, spawnpoint):
# Player will stuck here so move on...
continue
# We have a winner!
some_teleport_function_blah_blah(player_index)
# No need to go further...
return
# Uh oh, we didn't find a safe spawnpoint!
do_something_else(player_index)
Now since I would like to teleport for a certain distance it could happen that the coordinates of the destination are inside a wall or something. Basically what the code above does - checking if a player would be blocked. This is where I would need some explanation:
How does Ray() exactly work ? From the wiki(http://wiki.sourcepython.com/developing ... .trace.Ray) I can only tell that I can either provide 3 or 5 arguments and I am not sure what to pass as arguments.
Then for engine_trace.trace_ray() I could not find an entry in the wiki but in the source code (https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/engines/engines_trace_wrap.cpp) which tells me:
Syntax: Select all
.def("trace_ray",
&IEngineTrace::TraceRay,
"A version that simply accepts a ray (can work as a traceline or tracehull).",
args("ray", "mask", "filter", "trace")
)
The parameter "ray" is the ray instance, that is clear. But I don't really understand what "mask", "filter" and trace does.
Overall my understanding is that I create a ray instance with starting point and end point that somewhat will be the size of a players model and then either move the model(not the actual model but the sizes of the players model) along the 'trace' and check if it hit anything (like a wall) or only check the endpoint for any wall collision. If somebody could explain to me how this trace_ray works to check if the destination point would get the player stuck, that would be great.
The ultimate goal for me then is to make the teleport work in a way like this:
If the destination point would get the player stuck then try a destination point a little closer (I don't know, a fixed step like the player models width) and check again if that destination point would get the player stuck. Repeat that until a destination point will be valid and then teleport the player to those coordinates