Raised This Month: $ Target: $400
 0% 

Player Speed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-04-2009 , 04:09   Player Speed
Reply With Quote #1

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)
__________________

Last edited by Bad_Bud; 01-04-2009 at 04:16.
Bad_Bud is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-04-2009 , 04:23   Re: Player Speed
Reply With Quote #2

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); 
__________________

Last edited by xPaw; 01-04-2009 at 04:42.
xPaw is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-04-2009 , 04:24   Re: Player Speed
Reply With Quote #3

...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"?
__________________
Bad_Bud is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-04-2009 , 04:42   Re: Player Speed
Reply With Quote #4

watch code above
__________________
xPaw is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-04-2009 , 04:50   Re: Player Speed
Reply With Quote #5

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?
__________________

Last edited by Bad_Bud; 01-04-2009 at 04:56.
Bad_Bud is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-04-2009 , 05:04   Re: Player Speed
Reply With Quote #6

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))
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-04-2009 , 05:06   Re: Player Speed
Reply With Quote #7

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?
__________________
Bad_Bud is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-04-2009 , 05:18   Re: Player Speed
Reply With Quote #8

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]);
}
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-04-2009 , 05:20   Re: Player Speed
Reply With Quote #9

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.
__________________
Bad_Bud is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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