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

Push to target


Post New Thread Reply   
 
Thread Tools Display Modes
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 10-20-2014 , 15:14   Re: Push to target
Reply With Quote #11

OK updated code:
PHP Code:
#define MY_MIN_ANGLE -30.0
#define MY_MIN_HEIGHT 128.0

// ...

public Action:Command_TestiClientnArgs )
{
    
// ...
    
    
new Float:vecPlayerPos[3];
    
GetEntPropVectoriClientProp_Send"m_vecAbsOrigin"vecPlayerPos );
    
    new 
Float:vecPlayerMins[3];
    
GetEntPropVectoriClientProp_Send"m_vecMins"vecPlayerMins );
    new 
Float:vecPlayerMaxs[3];
    
GetEntPropVectoriClientProp_Send"m_vecMaxs"vecPlayerMaxs );

    new 
Float:vecTargetPos[3];
    
GetEntPropVectoriTargetProp_Send"m_vecAbsOrigin"vecTargetPos );

    
// ========================================================================== //

    // 3D direction
    
new Float:vecDirection[3];
    
SubtractVectorsvecTargetPosvecPlayerPosvecDirection );

    
// 2D direction
    
new Float:vecParabolaDir[3] = { 0.00.00.0 };
    
vecParabolaDir[0] = vecDirection[0];
    
vecParabolaDir[1] = vecDirection[1];

    new 
Float:flDistance NormalizeVectorvecDirectionvecDirection );
    new 
Float:flHDistance NormalizeVectorvecParabolaDirvecParabolaDir ); // horizontal distance

    
new Float:angDirection[3];
    
GetVectorAnglesvecDirectionangDirection );
    for( 
int i 0sizeofangDirection ); i++ )
        
angDirection[i] = NormalizeAngleangDirection[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;
    
GetAngleVectorsangDirectionvecDirectionNULL_VECTORNULL_VECTOR );
    
    
Vector vecScaledDir;
    
ScaleVectorvecDirectionflDistancevecScaledDir );
    new 
Float:flHeight vecScaledDir[2] * SineangDirection[0] );
    
flHeight += ( vecPlayerMaxs[2] - vecPlayerMins[2] ) * 0.5f;
    
flHeight FloatMaxflHeightMY_MIN_HEIGHT );
    
    new 
Float:flGravity FloatMax1.0GetConVarFloatsv_gravity ) );
    
    new 
Float:flForce SquareRoot( ( flHeight flGravity ) / PowSineangDirection[0] ), 2.0 ) );
    
    new 
Float:vecVelocity[3];
    
vecVelocity[0] = vecParabolaDir[0];
    
vecVelocity[1] = vecParabolaDir[1];
    
vecVelocity[2] = GetConVarFloatsm_my_multiplier );
    
ScaleVectorvecDirectionflForce );

    
// ========================================================================== //

    
TeleportEntityiClientNULL_VECTORNULL_VECTORvecDirection ); 
    return 
Plugin_Handled;
}

// ...

stock Float:NormalizeAngleFloat:flAngle )
{
    while( 
flAngle 180.0 )
        
flAngle -= 360.0;
    while( 
flAngle < -180.0 )
        
flAngle += 360.0;
    return 
flAngle;
}

stock Float:FloatMaxFloat:flValue1Float:flValue2 )
    return ( 
FloatCompareflValue1flValue2 ) >= 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.

Last edited by Leonardo; 10-20-2014 at 15:16.
Leonardo is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 10-20-2014 , 15:33   Re: Push to target
Reply With Quote #12

;O maybe someday I'll be able to make turrets like

https://www.youtube.com/watch?v=TXgMJ-mBlrs
__________________
Chdata is offline
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 01:15.


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