Velocity - Speed and Direction
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?
|
Re: Velocity - Speed and Direction
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.
|
Re: Velocity - Speed and Direction
Quote:
|
Re: Velocity - Speed and Direction
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 |
Re: Velocity - Speed and Direction
some example in a real code?
with: PHP Code:
|
Re: Velocity - Speed and Direction
PHP Code:
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. |
Re: Velocity - Speed and Direction
Quote:
|
All times are GMT -4. The time now is 14:31. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.