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

Getting velocity from angles


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 02-20-2011 , 13:20   Getting velocity from angles
Reply With Quote #1

Hey guys, im trying to replicate one valve function using SDKTools. This is the function:

Code:
CPipeBombProjectile::Create(Vector  const&, QAngle  const&, Vector  const&, Vector  const&, CBaseCombatCharacter *, float)
The function works very well, i can get the postion and angles using the SDKTools functions

Code:
GetClientEyePosition(client, Float:pos[3])
GetClientEyeAngles(client, Float:pos[3])
And the pipe bomb (grenade) will actually spawn. But, the problem is that it will just spawn with null velocity, and fall by gravity, without travelling at all in the air.

So, since im a noob at math, i asked one friend if he could help me, and he gave me this function in C++ (from Direct3D, he said).

Code:
vector newvector(float x,float y, float z)
{
nx =-(cos(z)*sin(y)*sin(x) - sin(z)*cos(x));
ny =-(sin(z)*sin(y)*sin(x) + cos(z)*cos(x));
nz =-(cos(y)*sin(x));

return Vector(nx, ny, nz);
}
So, i converted it in pawn like this:
Code:
stock GetVelFromAngles(const Float:angles[3], Float:velocity[3])
{
	new Float:x = angles[0];
	new Float:y = angles[1];
	new Float:z = angles[2];
	
	velocity[0] =-(Cosine(z)*Sine(y)*Sine(x) - Sine(z)*Cosine(x));
	velocity[1] =-(Sine(z)*Sine(y)*Sine(x) + Cosine(z)*Cosine(x));
	velocity[2] = 0.0;
}
Of course, this would just make a velocity with a power of "1", so i multiplied the vector later with 150.0 . The function works and the pipe bomb travels before falling. But the direction is always wrong. Doesnt matter where i look, it always goes in random directions or just goes above me.

Could anybody help me out to get the needed pipe bomb velocity, based on the position or angles i have? Supposing a power of 250.0 or less.

Is the 4th parameter of the function the reason of why it isnt working? (Right now im just passing a null vector {0.0, 0.0, 0.0}).

Any help would be really apreciated! Thanks!

PD: After some test, this is the result i got: (Pre: means before apllying the power of 150.0, and Post, after it)

Code:
Position: {3076.769287, 6740.875488, 1856.223144}
Angles: {-8.808827, -93.393051, 0.000000}
Velocity Pre: {-0.435838, -0.816224, -0.379238}
Velocity Post: {-65.375816, -122.433692, -56.885780}


Position: {3076.769287, 6740.875488, 1856.223144}
Angles: {2.311551, -92.129432, 0.000000}
Velocity Pre: {0.630071, -0.674845, -0.384179}
Velocity Post: {94.510681, -101.226791, -57.626964}


Position: {2997.039550, 6820.999023, 1720.113403}
Angles: {0.000000, 0.000000, 0.000000}
Velocity Pre: {0.000000, 1.000000, 0.000000}
Velocity Post: {0.000000, 150.000000, 0.000000}
honorcode23 is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 02-20-2011 , 13:45   Re: Getting velocity from angles
Reply With Quote #2

use GetAngleVectors to get the fwd vector, then normalise it then scale it to the speed you want.
blodia is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 02-21-2011 , 02:34   Re: Getting velocity from angles
Reply With Quote #3

Thanks alot for you help, it works as needed now
honorcode23 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 02-21-2011 , 03:46   Re: Getting velocity from angles
Reply With Quote #4

The another parameter may be angular velocity.
__________________
FaTony is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 02-21-2011 , 16:14   Re: Getting velocity from angles
Reply With Quote #5

Quote:
Originally Posted by FaTony View Post
The another parameter may be angular velocity.
Passing different values to this param will rotate the pipe bomb in different directions, so ya is angular vel .
honorcode23 is offline
Reply


Thread Tools
Display Modes

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 07:23.


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