AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   calculating different velocities from an origin (https://forums.alliedmods.net/showthread.php?t=162066)

liinuus 07-14-2011 11:07

calculating different velocities from an origin
 
I'm wondering if it would be possible to calculate an "knockback" velocity from an certain origin. like ex: if you are behind the origin you will fly backwards and if ur infront of the origin you will fly forwards. If this alredy exists on the forum then im sorry for my bad searching but i didnt rly know what search words to use

abdul-rehman 07-14-2011 11:09

Re: calculating different velocities from an origin
 
U need kind of a force field ? Right ?

liinuus 07-14-2011 11:22

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by abdul-rehman (Post 1510598)
U need kind of a force field ? Right ?

no i was thinking of adding an knockback velocity to an explosion, but it would look silly if all the players flew at the same direction even when theyre on different sides of the explosion

fysiks 07-14-2011 13:52

Re: calculating different velocities from an origin
 
You just need to find the vector from the origin (explosion) to the player and use that direction as the direction of the player's velocity (you would need to scale the magnitude appropriately).

liinuus 07-14-2011 14:20

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by fysiks (Post 1510697)
You just need to find the vector from the origin (explosion) to the player and use that direction as the direction of the player's velocity (you would need to scale the magnitude appropriately).

yes thats the part i dont know how to do, i havnt had much experience in vectors so i do not know how i could use it to get the direction, everything else i know how to do

abdul-rehman 07-14-2011 14:57

Re: calculating different velocities from an origin
 
Lets give you an idea:
Code:
new Float:explosion_origin[3] // Var which will hold the origin where you want the explosion to take // Retrieve player's origin new Float:player_origin[3] pev( id, pev_origin, player_origin ) // We will get a vector pointing from explosion's origin towards the player // eg: we always get a vector from point.A to point.B if we substract point.A's origin from point.B's origin. new Float:player_vector[3] player_vector[0] = player_origin[0] - explosion_origin[0] player_vector[1] = player_origin[1] - explosion_origin[1] player_vector[2] = player_origin[2] - explosion_origin[2] // We normalize the vector. Basically a normalized vector is vector with a length of 1 unit xs_vec_normalize( player_vector, player_vector ) // Now you can increase the vector's magnitude according to the player's distance from the origin (you can change its magnitude (length) by multipling it by a scalar)

For more info you can read this tutorial coz that is how i learned this vector stuff.
https://forums.alliedmods.net/showthread.php?t=91474

liinuus 07-14-2011 15:33

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by abdul-rehman (Post 1510732)
Lets give you an idea:
Code:
new explosion_origin[3] // Var which will hold the origin where you want the explosion to take // Retrieve player's origin new player_origin[3] pev( id, pev_origin, player_origin ) // We will get a vector pointing from explosion's origin towards the player // eg: we always get a vector from point.A to point.B if we substract point.A's origin from point.B's origin. new player_vector[3] player_vector[0] = player_origin[0] - explosion_origin[0] player_vector[1] = player_origin[1] - explosion_origin[1] player_vector[2] = player_origin[2] - explosion_origin[2] // We normalize the vector. Basically a normalized vector is vector with a length of 1 unit xs_vec_normalize( player_vector, player_vector ) // Now you can increase the vector's magnitude according to the player's distance from the origin (you can change its magnitude (length) by multipling it by a scalar)

For more info you can read this tutorial coz that is how i learned this vector stuff.
https://forums.alliedmods.net/showthread.php?t=91474

thankls i will try and test an bit, btw dsnt pev_origin need an Float value?

abdul-rehman 07-14-2011 15:37

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by liinuus (Post 1510768)
thankls i will try and test an bit, btw dsnt pev_origin need an Float value?

Sorry i forgot that, editted it.

liinuus 07-14-2011 15:46

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by abdul-rehman (Post 1510774)
Sorry i forgot that, editted it.

shudnt the vector be a Float aswell?

abdul-rehman 07-14-2011 15:59

Re: calculating different velocities from an origin
 
Quote:

Originally Posted by liinuus (Post 1510781)
shudnt the vector be a Float aswell?

Depends, if you substract 2 Float origins then you will get a Float vector (unless u round it off) like i did above


All times are GMT -4. The time now is 00:49.

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