AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player Speed (https://forums.alliedmods.net/showthread.php?t=83089)

Bad_Bud 01-04-2009 04:09

Player Speed
 
How would one calculate the speed of a player as a single number based on the player's three velocities in X, Y, and Z?

(I'm actually only interested in the speed based on the X and the Y)

xPaw 01-04-2009 04:23

Re: Player Speed
 
PHP Code:

new g_Velocity[3];
pev(indexpev_velocityg_Velocity);

g_Velocity[0] = 114.0;
g_Velocity[1] = 372.0;
// g_Velocity[2] = ... // Z

set_pev(indexpev_velocityg_Velocity); 


Bad_Bud 01-04-2009 04:24

Re: Player Speed
 
...that's what I already know. I want to know what the speed is, based on that -- not how to set it.

For instance, if the max player speed is 500, and the player is walking down the X axis, then X = 500 and Y = 0.

However, I want to work from the other direction. If I'm given that X = 114 and Y = 372, then what is the combined "speed"?

xPaw 01-04-2009 04:42

Re: Player Speed
 
watch code above

Bad_Bud 01-04-2009 04:50

Re: Player Speed
 
No. I don't want to set anything, I just want to know what the combined speed of the two vectors is, but I have nooo idea how to do vector addition in this way.

PHP Code:

new g_Velocity[3];
pev(indexpev_velocityg_Velocity);
 
client_print(id,print_chat,"%f",g_Velocity[0]);//Will print 114.0.
client_print(id,print_chat,"%f",g_Velocity[1]);//Will print 372.0.
 
//CALCULATE SPEED HERE, BUT HOW? 

Perhaps another explanation of what I'm looking for...

What if someone had done the following:

PHP Code:

new g_Velocity[3];
velocity_by_aim(index,500,g_Velocity);
set_pev(index,pev_velocity,g_Velocity); 

Consider that gravity is set to 0, and there is nothing else that will slow the player down.

Our problem is set one second after the velocity_by_aim has been applied to my character. How would I, based on my pev_velocity, calculate that I am moving at this speed of 500?

ConnorMcLeod 01-04-2009 05:04

Re: Player Speed
 
new g_Velocity[3];
pev(index, pev_velocity, g_Velocity);
g_Velocity[2] = 0

// speed is a float :
client_print(id,print_center,"%f", vector_lengh(g_Velocity))

Bad_Bud 01-04-2009 05:06

Re: Player Speed
 
Holy s***! vector_length was exactly what I was looking for. Thank you so much!

Just curious, but does anyone have any idea how that length is calculated within that function?

ConnorMcLeod 01-04-2009 05:18

Re: Player Speed
 
From xs.inc (result will be the same but vector_lengh might be faster) :

Float: xs_vec_len(const Float:vec[])
{
return xs_sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
}

Bad_Bud 01-04-2009 05:20

Re: Player Speed
 
That's really weird... I had tried to calculate that and I didn't get the same answer. I was so confused as to where I had gone wrong.

I guess I typed something in wrong. Either way, thank you very much.


All times are GMT -4. The time now is 09:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.