Page 1 of 1

Move player behind another

Posted: Mon May 21, 2018 12:24 am
by arawra
My vector math isn't the best :P

I want to be able to position a player behind another. This code would have worked, except for the player clipping on enemy players :\


Syntax: Select all

@SayCommand('test')
def test(command, index, teamOnly):
player = Player(index)
if player.get_view_player():
target = player.get_view_player()
target.origin = player.origins
target.set_view_angle(player.get_view_angle())
Repeat(playerPush, args=(target, None)).start(.05, 1)

def playerPush(player, notUsed=None):
player.push(-500,-500)



E: I think I can do this by converting to/from rectangular and polar coordinates...

Re: Move player behind another

Posted: Mon May 21, 2018 1:06 am
by arawra
My solution. If anyone has suggestions I'd like to hear them!

Syntax: Select all

@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 = -50 * math.cos(angle)
y = -50 * math.sin(angle)
player.origin = Vector(target.origin[0] + x, target.origin[1] + y, target.origin[2])
player.set_view_angle(angles)

Re: Move player behind another

Posted: Mon May 21, 2018 9:24 pm
by VinciT
Your solution works great, but I kept getting stuck in the ground on slopes.
I'd probably just add a couple of checks to see if there's enough space behind the target.

I took the is_in_solid() function from the Entity class and used it to check if the new position has enough space for the player to teleport to.



You could shoot a trace ray at the ground from the target and get the plane.normal to see if they are standing on a slope, and then properly calculate the height of the new position, instead of just increasing the height like I did.

Oh and if you're moving while teleporting behind the target, the velocity will stay with you. So maybe try negating the velocity with the teleport function?