Page 1 of 1
Get units/s
Posted: Fri Jan 15, 2016 1:47 pm
by decompile
HeyGuys,
Just want to ask how you convert the velocity to units per second?
Like in ES you could use:
Syntax: Select all
vecmath.vector(525, 3500, 10).length()
Syntax: Select all
def playerVelocity(self):
return PlayerEntity(self.index).velocity
and it seems like it has no .length() attribute and it only returns the vector.
Posted: Fri Jan 15, 2016 1:57 pm
by iPlayer
Given the vector v(x, y, z), you can calculate its length this way:
I believe SP provides .get_length method for Vectors
Posted: Fri Jan 15, 2016 2:18 pm
by decompile
Thank you, worked.
Syntax: Select all
return PlayerEntity(self.index).velocity.get_length()
Posted: Fri Jan 15, 2016 2:20 pm
by satoon101
iPlayer wrote:I believe SP provides .get_length method for Vectors
Indeed:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/mathlib/mathlib_wrap.cpp#L139
Though we could (should?) change that to be a property named
length.
Posted: Fri Jan 15, 2016 3:30 pm
by iPlayer
What about __len__ method? Or is it too implicit?
Posted: Fri Jan 15, 2016 4:11 pm
by necavi
__len__ is pretty explicitly for containers only. I don't see much benefit to doing len(vector) over vector.length, really.
Re: Get units/s
Posted: Mon Apr 25, 2016 9:53 pm
by decompile
How can I get the the units without z? So the actuall forward speed?
Re: Get units/s
Posted: Mon Apr 25, 2016 10:08 pm
by iPlayer
Use the first formula from the picture I posted
Re: Get units/s
Posted: Mon Apr 25, 2016 10:19 pm
by satoon101
To easily do that, you can always zero out the z value of the Vector:
Syntax: Select all
velocity = Player(index).velocity
velocity.z = 0
return velocity.length