AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Knockback Wrong Calculation (https://forums.alliedmods.net/showthread.php?t=329468)

AnimalMonster 12-25-2020 17:51

Knockback Wrong Calculation
 
Hey, i try to make the zombie bomb from cso based on player's velocity and user's fistance from the explosion but the knockback power to be 100.0 + player's velocity based on the distance of the player from the bomb, longer distance = less knockback.

But.. didn't work as expected, i know it 100% is wrong but yeah.

PHP Code:

fl_Velocity[0] = (speed VicVelocity[0]) * ((EntOrigin[0] - VicOrigin[0]) / fl_Time)
fl_Velocity[1] = (speed VicVelocity[1]) * ((EntOrigin[1] - VicOrigin[1]) / fl_Time)
fl_Velocity[2] = (speed VicVelocity[2]) * ((EntOrigin[2] - VicOrigin[2]) / fl_Time)

fl_Time get_distance_f(EntOriginVicOrigin) / speed 

Edit: nevermind, i got it working the way i wanted eliminating the VicVelocity but
I put the speed as first thing multiplied by entorigin - vicorigin * fl_Time everything / 2

Natsheh 12-25-2020 19:27

Re: Knockback Wrong Calculation
 
this is kind bad calculations show what is fl_Time is equal to... or atleast the calculation function.

i'm certain there's a better way to achieve such thing.


Edit : Try this ::arrow:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <xs>

#define VERSION "1.0"
#define AUTHOR "Natsheh"


player_explosion_knockback(victimFloat:fExpOrigin[3], Float:fExpShockwaveRadius=500.0Float:fExpShockwavePower=500.0)
{
    new 
Float:fOrigin[3], Float:fDistVec[3];
    
pev(victimpev_originfOrigin);
    
    
xs_vec_sub(fExpOriginfOriginfDistVec);
    
    new 
Float:g_fTemp;
    
// victim is in the range of the shockwave explosion!
    
if((g_fTemp=xs_vec_len(fDistVec)) <= fExpShockwaveRadius)
    {
        new 
Float:fPower fExpShockwavePower * ( 1.0 - ( g_fTemp floatmin(fExpShockwaveRadius1.0) ) ), Float:fVelo[3], Float:fKnockBackVelo[3];
        
        
pev(victimpev_velocityfVelo);
        
xs_vec_normalize(fDistVecfKnockBackVelo);
        
xs_vec_mul_scalar(fKnockBackVelofPowerfKnockBackVelo);
        
xs_vec_add(fVelofKnockBackVelofVelo);
        
set_pev(victimpev_velocityfVelo);
    }



AnimalMonster 12-26-2020 08:05

Re: Knockback Wrong Calculation
 
Quote:

Originally Posted by Natsheh (Post 2730108)
this is kind bad calculations show what is fl_Time is equal to... or atleast the calculation function.

i'm certain there's a better way to achieve such thing.


Edit : Try this ::arrow:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <xs>

#define VERSION "1.0"
#define AUTHOR "Natsheh"


player_explosion_knockback(victimFloat:fExpOrigin[3], Float:fExpShockwaveRadius=500.0Float:fExpShockwavePower=500.0)
{
    new 
Float:fOrigin[3], Float:fDistVec[3];
    
pev(victimpev_originfOrigin);
    
    
xs_vec_sub(fExpOriginfOriginfDistVec);
    
    new 
Float:g_fTemp;
    
// victim is in the range of the shockwave explosion!
    
if((g_fTemp=xs_vec_len(fDistVec)) <= fExpShockwaveRadius)
    {
        new 
Float:fPower fExpShockwavePower * ( 1.0 - ( g_fTemp floatmin(fExpShockwaveRadius) ) ), Float:fVelo[3], Float:fKnockBackVelo[3];
        
        
pev(victimpev_velocityfVelo);
        
xs_vec_normalize(fDistVecfKnockBackVelo);
        
xs_vec_mul_scalar(fKnockBackVelofPowerfKnockBackVelo);
        
xs_vec_add(fVelofKnockBackVelofVelo);
        
set_pev(victimpev_velocityfVelo);
    }



Never mind i got more problems so i decided to use x = ((distance/max)-1.0)*(-1.0) but also didn t work great. the velocity would have been equal to speed * x.
I tried to get a invers-proportional value from 0 to 1.0 that based on the distance of the player on bomb, did work but not as expected since only on 0 would kick you great.
fl_Time was equal to get_distance_f(EntOrigin, VicOrigin) / speed.

So, what was the problem in my calculation? I think it is perfect rn and works great, i will also try yours because it may be better but the thing is, it's kinda hilarious that i could do that thing without these xs natives.

Edit: yours didn't work at all...


All times are GMT -4. The time now is 14:08.

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