Changing player velocity

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

Changing player velocity

Postby arawra » Fri May 29, 2015 9:50 am

I want to be able to make players leap. I thought this would be the way to do so, but it doesn't have the desired result. A player's velocity doesn't seem to change at all.

Syntax: Select all

from events import Event

from mathlib import Vector

from players.entity import PlayerEntity
from players.helpers import *

@Event
def player_jump(ev):
player = PlayerEntity(index_from_userid(ev.get_int('userid')))
lunge(player)

def lunge(player):
x_vel = player.velocity.x * 200
y_vel = player.velocity.y * 200
player.velocity = Vector(x_vel, y_vel, 200)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Fri May 29, 2015 11:31 am

You need to use, player.teleport(None, None, velocity_cector) ti "apply" a velocity, those attributes are read only by the engine. You could also look at basevelocity but teleport is definitively better
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Fri Jan 22, 2016 4:03 pm

Having weird problems,

Syntax: Select all

<Player>.teleport(None, None, Vector(0, 0, 0))
doesnt work but

Syntax: Select all

<Player>.teleport(origin, None, Vector(0, 0, 0)
works
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sat Apr 16, 2016 12:26 pm

Still having problems with that on CS:S Windows:
When I want to reset the players speed.

Syntax: Select all

<Player>.teleport(<Player>.origin, None, Vector())

or

Syntax: Select all

<Player>.teleport(None, None, Vector())

both doesnt work..
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Apr 16, 2016 12:37 pm

Well, that code works. It doesn't do what you want, that's different. When you use a null vector as velocity, you tells the function to apply nothing. In order to stop the motion of a player, you need to apply his current velocity reverted.[python]<Player>.teleport(None, None, player.velocity.negate())[/python]
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Sat Apr 16, 2016 1:38 pm

Syntax: Select all

player.velocity.negate()
negates it in-place and returns nothing. It won't work that way.

Try this

Syntax: Select all

velocity = player.velocity    # Save shortcut value to a variable
velocity.negate() # Multiply vector by -1
player.base_velocity = velocity # Use base_velocity to apply velocity to a player

or this

Syntax: Select all

velocity = player.velocity    # Save shortcut value to a variable
velocity.negate() # Multiply vector by -1
player.teleport(None, None, velocity) # Use teleport to apply velocity to a player
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 136 guests