[CS:S] Worldspawn touch problem
Posted: Sun Feb 14, 2021 6:46 pm
Hey guys,
I'm trying to determine when you touch the ground. I tried multiple ways, including this:
The problem is, it does not work reliably. When I jump around it does not consistently work. I also tried start_touch, with even worse results.
Groundflag is not an option I can use, as my plugin involves beeing hit by flashes at the feet, which sometimes is counted as beeing on the ground for some reason.
My idea now would be to make a trace going down from your feet to check if the ground is away more then x units. The problem with this is that I'm not familiar with traces + their performance for such a check. I tried this code:
But this is not as reliable yet as I wished it would be, as the distance you last get can vary from 0 to 10 or even more units. Also this would not check for flashes below you yet I guess.
Any ideas for different ways how to consistently check for the ground?
I'm trying to determine when you touch the ground. I tried multiple ways, including this:
Syntax: Select all
@EntityPreHook(EntityCondition.equals_entity_classname('player'), 'touch')
def Entity_StartTouch(args):
entity = make_object(Entity, args[1]) #this is player
try:
touching = make_object(Entity, args[0])
except:
return
if entity.classname == "worldspawn": print(entity.classname)
if touching.classname == "worldspawn": print(touching.classname)
The problem is, it does not work reliably. When I jump around it does not consistently work. I also tried start_touch, with even worse results.
Groundflag is not an option I can use, as my plugin involves beeing hit by flashes at the feet, which sometimes is counted as beeing on the ground for some reason.
My idea now would be to make a trace going down from your feet to check if the ground is away more then x units. The problem with this is that I'm not familiar with traces + their performance for such a check. I tried this code:
Syntax: Select all
@OnTick
def _tick():
for player in PlayerIter('alive'):
if not player.flags & PlayerStates.ONGROUND:
destination = Vector(player.origin[0],player.origin[1],player.origin[2]-1000)
# Get a new trace instance
trace = GameTrace()
# Trace from the player's feet to the destination
engine_trace.trace_ray(
# This matches the player's bounding box from his feets to
# the destination
Ray(player.origin, destination, player.mins, player.maxs),
# This collides with everything
ContentMasks.ALL,
# This ignore nothing but the player himself
TraceFilterSimple((player,)),
# The trace will contains the results
trace
)
# If the trace did hit, that means there was obstruction along the way
if trace.did_hit():
if trace.end_position.get_distance(player.origin) >= 0 and trace.end_position.get_distance(player.origin) <= 10:
# So the end of our trace becomes our destination
print('hit')
But this is not as reliable yet as I wished it would be, as the distance you last get can vary from 0 to 10 or even more units. Also this would not check for flashes below you yet I guess.
Any ideas for different ways how to consistently check for the ground?