Move player behind another

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Move player behind another

Postby arawra » Mon May 21, 2018 12:24 am

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...
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Move player behind another

Postby arawra » Mon May 21, 2018 1:06 am

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)
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Move player behind another

Postby VinciT » Mon May 21, 2018 9:24 pm

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?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 45 guests