Raised This Month: $ Target: $400
 0% 

calculating different velocities from an origin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
liinuus
Senior Member
Join Date: Apr 2010
Old 07-14-2011 , 11:07   calculating different velocities from an origin
Reply With Quote #1

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
liinuus is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-14-2011 , 11:09   Re: calculating different velocities from an origin
Reply With Quote #2

U need kind of a force field ? Right ?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
liinuus
Senior Member
Join Date: Apr 2010
Old 07-14-2011 , 11:22   Re: calculating different velocities from an origin
Reply With Quote #3

Quote:
Originally Posted by abdul-rehman View Post
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
liinuus is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-14-2011 , 13:52   Re: calculating different velocities from an origin
Reply With Quote #4

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).
__________________
fysiks is offline
liinuus
Senior Member
Join Date: Apr 2010
Old 07-14-2011 , 14:20   Re: calculating different velocities from an origin
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
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
liinuus is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-14-2011 , 14:57   Re: calculating different velocities from an origin
Reply With Quote #6

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
__________________

My Plugins For ZP

Inactive due to College and Studies

Last edited by abdul-rehman; 07-14-2011 at 15:59.
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
liinuus
Senior Member
Join Date: Apr 2010
Old 07-14-2011 , 15:33   Re: calculating different velocities from an origin
Reply With Quote #7

Quote:
Originally Posted by abdul-rehman View Post
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?
liinuus is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-14-2011 , 15:37   Re: calculating different velocities from an origin
Reply With Quote #8

Quote:
Originally Posted by liinuus View Post
thankls i will try and test an bit, btw dsnt pev_origin need an Float value?
Sorry i forgot that, editted it.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
liinuus
Senior Member
Join Date: Apr 2010
Old 07-14-2011 , 15:46   Re: calculating different velocities from an origin
Reply With Quote #9

Quote:
Originally Posted by abdul-rehman View Post
Sorry i forgot that, editted it.
shudnt the vector be a Float aswell?
liinuus is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-14-2011 , 15:59   Re: calculating different velocities from an origin
Reply With Quote #10

Quote:
Originally Posted by liinuus View Post
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
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
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 00:49.


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