OK updated code:
PHP Code:
#define MY_MIN_ANGLE -30.0
#define MY_MIN_HEIGHT 128.0
// ...
public Action:Command_Test( iClient, nArgs )
{
// ...
new Float:vecPlayerPos[3];
GetEntPropVector( iClient, Prop_Send, "m_vecAbsOrigin", vecPlayerPos );
new Float:vecPlayerMins[3];
GetEntPropVector( iClient, Prop_Send, "m_vecMins", vecPlayerMins );
new Float:vecPlayerMaxs[3];
GetEntPropVector( iClient, Prop_Send, "m_vecMaxs", vecPlayerMaxs );
new Float:vecTargetPos[3];
GetEntPropVector( iTarget, Prop_Send, "m_vecAbsOrigin", vecTargetPos );
// ========================================================================== //
// 3D direction
new Float:vecDirection[3];
SubtractVectors( vecTargetPos, vecPlayerPos, vecDirection );
// 2D direction
new Float:vecParabolaDir[3] = { 0.0, 0.0, 0.0 };
vecParabolaDir[0] = vecDirection[0];
vecParabolaDir[1] = vecDirection[1];
new Float:flDistance = NormalizeVector( vecDirection, vecDirection );
new Float:flHDistance = NormalizeVector( vecParabolaDir, vecParabolaDir ); // horizontal distance
new Float:angDirection[3];
GetVectorAngles( vecDirection, angDirection );
for( int i = 0; i < sizeof( angDirection ); i++ )
angDirection[i] = NormalizeAngle( angDirection[i] );
new Float:flOldPitch = angDirection[0];
new Float:flPitchDiff = ( MY_MIN_ANGLE - angDirection[0] );
if( angDirection[0] > MY_MIN_ANGLE )
angDirection[0] = MY_MIN_ANGLE;
GetAngleVectors( angDirection, vecDirection, NULL_VECTOR, NULL_VECTOR );
Vector vecScaledDir;
ScaleVector( vecDirection, flDistance, vecScaledDir );
new Float:flHeight = vecScaledDir[2] * Sine( angDirection[0] );
flHeight += ( vecPlayerMaxs[2] - vecPlayerMins[2] ) * 0.5f;
flHeight = FloatMax( flHeight, MY_MIN_HEIGHT );
new Float:flGravity = FloatMax( 1.0, GetConVarFloat( sv_gravity ) );
new Float:flForce = SquareRoot( ( flHeight * 2 * flGravity ) / Pow( Sine( angDirection[0] ), 2.0 ) );
new Float:vecVelocity[3];
vecVelocity[0] = vecParabolaDir[0];
vecVelocity[1] = vecParabolaDir[1];
vecVelocity[2] = GetConVarFloat( sm_my_multiplier );
ScaleVector( vecDirection, flForce );
// ========================================================================== //
TeleportEntity( iClient, NULL_VECTOR, NULL_VECTOR, vecDirection );
return Plugin_Handled;
}
// ...
stock Float:NormalizeAngle( Float:flAngle )
{
while( flAngle > 180.0 )
flAngle -= 360.0;
while( flAngle < -180.0 )
flAngle += 360.0;
return flAngle;
}
stock Float:FloatMax( Float:flValue1, Float:flValue2 )
return ( FloatCompare( flValue1, flValue2 ) >= 0 ? flValue1 : flValue2 );
And this works perflectly nice with an angle below 45.
I'm pretty sure I did a big mess with vectors normalization.
Gonna check everything again tomorrow.