Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #teleport_behind_test.py
- import math
- from mathlib import Vector
- from commands.say import SayCommand
- from players.entity import Player
- from entities import BaseEntityGenerator
- from engines.trace import engine_trace
- from engines.trace import ContentMasks
- from engines.trace import GameTrace
- from engines.trace import Ray
- from engines.trace import TraceFilterSimple
- @SayCommand('test')
- def test(command, index, teamOnly):
- player = Player(index)
- #message(player.origin)
- target = player.get_view_player()
- if target:
- angles = target.get_view_angle()
- angle = math.radians(target.get_view_angle()[1]) # (0, angle)
- x = -40 * math.cos(angle)
- y = -40 * math.sin(angle)
- new_position = Vector(
- target.origin[0] + x,
- target.origin[1] + y,
- target.origin[2])
- # Check if there's enough space behind the target.
- trace = check_space(new_position, player.mins, player.maxs)
- # Did the trace hit something solid?
- if trace.did_hit():
- # Increase the height(z) of the new position,
- # in case the target was on sloped terrain.
- new_position[2] += 20
- # Is there enough space now?
- trace2 = check_space(new_position, player.mins, player.maxs)
- if trace2.did_hit():
- # There's still something solid behind the target.
- # Could be a wall or some other object.
- return
- # teleport(position, rotation, velocity)
- player.teleport(new_position, None, None)
- player.set_view_angle(angles)
- def check_space(position, mins, maxs):
- mask=ContentMasks.ALL
- generator=BaseEntityGenerator
- ray = Ray(position, position, mins, maxs)
- trace = GameTrace()
- engine_trace.trace_ray(ray, mask, TraceFilterSimple(generator()), trace)
- return trace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement