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}