Raised This Month: $51 Target: $400
 12% 

Velocity - Speed and Direction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 06-24-2023 , 00:15   Velocity - Speed and Direction
Reply With Quote #1

Hi, I was wondering, if I have a certain Velocity stored in a array, we know that velocity is a vector, it has direction and speed, but how can I change its speed, keeping its same direction?
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-24-2023 , 16:17   Re: Velocity - Speed and Direction
Reply With Quote #2

Multiply it by a number. If you're not familiar with how vectors work, this just mean multiply each of the three values by the same number. If you want to double the speed, multiply each of the three values by 2.
__________________

Last edited by fysiks; 06-24-2023 at 16:19.
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 06-24-2023 , 16:24   Re: Velocity - Speed and Direction
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Multiply it by a number. If you're not familiar with how vectors work, this just mean multiply each of the three values by the same number. If you want to double the speed, multiply each of the three values by 2.
What if I want to multiply it by 5 but I don't want its speed to exceed "X" amount?
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-24-2023 , 16:30   Re: Velocity - Speed and Direction
Reply With Quote #4

If you want to set it to a specific value, you need to calculate the "unit vector" (a vector with magnitude of 1). Then, you can multiply that by the exact speed value that you want. There is a bunch of info on the internet to calculate this, I'd recommend checking some of them out. I think there might be some functions in AMX Mod X to help with this, I just haven't found them yet (it's been a while since I've needed to use vector stuff).

EDIT: Here is a function to normalize the vector (to get the unit vector): http://www.amxmodx.org/api/xs/xs_vec_normalize
__________________

Last edited by fysiks; 06-24-2023 at 16:34.
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 06-24-2023 , 21:55   Re: Velocity - Speed and Direction
Reply With Quote #5

some example in a real code?

with:

PHP Code:

new Float:__fl_Velocity[3];
entity_get_vectoridEV_VEC_velocity__fl_Velocity );

// Multiply speed

entity_set_vectoridEV_VEC_velocity__fl_Velocity ); 
MrPickles is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-26-2023 , 08:31   Re: Velocity - Speed and Direction
Reply With Quote #6

PHP Code:
#include <xs>
#include <engine>

client_prethink(id)
{
static 
Float:__fl_Velocity[3];
entity_get_vectoridEV_VEC_velocity__fl_Velocity );

if(
xs_vec_len(__fl_Velocity) > 100.0)
{
   
xs_vec_normalize(__fl_Velocity__fl_Velocity);
   
xs_vec_multiple(__fl_Velocity100.0__fl_Velocity);
}

entity_set_vectoridEV_VEC_velocity__fl_Velocity ); 

Here in the previous code it will limit the maximum speed for players to 100 units/sec


Keep in mind vector angles wont change if you divide the vector by its length and it will be called a unit vector, if you've a unit vector and want to give it a magnitude you've to multiplied it with a number that number will be called a vector scalar.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-27-2023 at 05:30.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-26-2023 , 23:37   Re: Velocity - Speed and Direction
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
PHP Code:
#include <xs>
#include <engine>

client_prethink(id)
{
static 
Float:__fl_Velocity[3];
entity_get_vectoridEV_VEC_velocity__fl_Velocity );

if(
xs_vec_len(__fl_Velocity) > 100.0)
{
   
xs_vec_normalize(__fl_Velocity__fl_Velocity);
   
xs_vec_multiple(__fl_Velocity100.0__fl_Velocity);
}

entity_set_vectoridEV_VEC_velocity__fl_Velocity ); 

Here in the previous code it will limit the maximum speed for players to 100 units/sec


Keep in mind vector angles wont change if you divide the vector by its length and it will be called a unit vector, if you've a unit vector and want to give it a magnitude you've to multiplied it with a number that number will be called a vector scalar.
"scalar" and "vector" are two mutually exclusive terms in this context. I guess you probably mean that it's a "scaler" which probably just makes it super confusing. Just call it a number. If you really need a name for it you'd probably just call it "the magnitude".
__________________
fysiks 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 13:04.


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