Page 1 of 1
Changing player velocity
Posted: Fri May 29, 2015 9:50 am
by arawra
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)
Posted: Fri May 29, 2015 11:31 am
by L'In20Cible
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
Posted: Fri Jan 22, 2016 4:03 pm
by decompile
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
Posted: Sat Apr 16, 2016 12:26 pm
by decompile
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..
Posted: Sat Apr 16, 2016 12:37 pm
by L'In20Cible
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]
Posted: Sat Apr 16, 2016 1:38 pm
by iPlayer
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