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

Modifying movement code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mrshark45
Member
Join Date: Jan 2016
Old 01-15-2021 , 02:48   Modifying movement code
Reply With Quote #1

I'm trying to solve a well known bug, when surfing with high fps sometimes you get stuck, I wrote a plugin that kind of moves you back a frame everytime you get stuck, it worked well on singleplayer server, but on a dedicated server it lagged a lot, so I though that maybe the plugin was not efficent enough so I tried to write a module, but I ran into the same problem: video ( first half of the video is without the module and the rest with).
This is the module code :
PHP Code:
vec3_t lastVel[33];
vec3_t lastOrg[33];


bool is_vector_zero(struct vec3_t v){
    return 
v[0] == 0.0 && v[1] == 0.0;
}

bool IsUserSurfing(struct playermove_spMove){
    if (!
pMove->deadflag)
    {
        if (
pMove->onground)
        {
            
vec3_t end;
            
pmtrace_t trace;
            for (
int i 03i++)
            {
                
float flScale pMove->frametime pMove->velocity[i];
                
end[i] = pMove->origin[i] + flScale;
            }
            
            
trace pMove->PM_PlayerTrace(pMove->originendPM_NORMAL, -1);
            
vec3_t plane trace.plane.normal;
            if (
plane[2] != 0.0 && plane[2] != 1.0) {
                return 
1;
            }

        }
    }
    return 
0;
}

void PM_Move(struct playermove_s *pMoveqboolean server) {
    if (
IsUserSurfing(pMove)) {
        
int player pMove->player_index;
        
vec3_t vel pMove->velocity;
        
vec3_t org pMove->origin;

        if (!
is_vector_zero(pMove->velocity)) {
            
lastVel[player] = vel;
            
lastOrg[player] = org;
        }
        else if (!
is_vector_zero(lastVel[player])) {
            
pMove->velocity lastVel[player];
            
lastOrg[player][2] += 0.1;
            
pMove->origin lastOrg[player];
        }
        
    }
    
 } 
I hooked PM_Move and checked when the player gets stuck while surfing and setted his previous velocity and moved him 0.1 units upwards to unstuck him.
As I said it worked very well on a singleplayer server but when used on a dedicated one it lagged, like everytime you got stucked you will notice, it drags you forward, I think that maybe the player's ping may be causing this.
I was wondering if I can modify directly the movement code, like *supercede* the original code with mine?
I'm kind of new to writing modules, started 2-3 days ago to learn.
Is the movement code for players running on client side, is it something that I can do to modify it more efficiently?
Or correct it in some way, like in PM_Move_Post?
mrshark45 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-18-2021 , 15:58   Re: Modifying movement code
Reply With Quote #2

Quote:
Originally Posted by mrshark45 View Post
Is the movement code for players running on client side
Yeah, and it's probably client misprediction that causes that. I believe there's no way of avoiding it, unless you eliminate the root cause of getting stuck in place (and replicate that to clients somehow).
__________________
klippy is offline
mrshark45
Member
Join Date: Jan 2016
Old 01-19-2021 , 06:59   Re: Modifying movement code
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
Yeah, and it's probably client misprediction that causes that. I believe there's no way of avoiding it, unless you eliminate the root cause of getting stuck in place (and replicate that to clients somehow).
That's what I'm asking if there's a way to prevent it before it's happening...
mrshark45 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 12:15.


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