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

register_touch and set_pev


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 04-22-2015 , 00:35   register_touch and set_pev
Reply With Quote #1

When using register_touch, for example

PHP Code:
register_touch("func_wall",  "player""Touch_Wall"); 
Within Touch_Wall function, set_pev command does not seem to work.
For instance

PHP Code:
public Touch_Wall(id)
{
      
set_pev(idpev_velocityFloat:{0.0,0.0,0.0});

The above code is supposed to stop player's movement but it doesn't.
But if I use

PHP Code:
public Touch_Wall(id)
{
      
set_task(0.1"Task_Wall"id);
}

public 
Task_Wall(id)
{
      
set_pev(idpev_velocityFloat:{0.0,0.0,0.0});

it works just fine.
Any ideas why?

Thanks in advance.
vitorrossi is offline
hzqst
Senior Member
Join Date: Jul 2008
Old 04-22-2015 , 02:23   Re: register_touch and set_pev
Reply With Quote #2

your "touch_wall" is called from engine:
PHP Code:
void SV_RunCmd(usercmd_t *ucmdint random_seed)
{
...
...

    if (
host_client->edict->v.solid)
    {
        
vec3_t vel;
        
pmtrace_t *tr;

        
SV_LinkEdict(sv_playertrue);
        
        
//Engine save current player's velocity here
        
VectorCopy(sv_player->v.velocityvel);

        for (
0pmove->numtouchi++)
        {
            
tr = &pmove->touchindex[i];
            
ent EDICT_NUM(pmove->physents[tr->hitgroup].info);

            
SV_ConvertPMTrace(&tracetrent);

            
VectorCopy(tr->deltavelocitysv_player->v.velocity)
            
SV_Impact(entsv_player, &trace);
        }

        
//and recover velocity here in case someone modify player's velocity
        
VectorCopy(velsv_player->v.velocity);
    }
...


and

PHP Code:

void SV_Impact
(edict_t *e1edict_t *e2trace_t *ptrace)
{
...
...
    if (
e1->v.solid != SOLID_NOT)
    {
        
SV_SetGlobalTrace(ptrace);
        
gEntityInterface.pfnTouch(e1e2);
    }

    if (
e2->v.solid != SOLID_NOT)
    {
        
SV_SetGlobalTrace(ptrace);
        
gEntityInterface.pfnTouch(e2e1);
    }
...
...

it's obvious that your new velocity change in
PHP Code:
gEntityInterface.pfnTouch(e1e2); 
is overwritten here
PHP Code:
VectorCopy(velsv_player->v.velocity); 
so the change has no effect. and you have no access to the "vec3_t vel" in engine 's stack memory.
you'd better do phys calculation like changing velocity in playermove code (PM_Move), or set a flags then set new velocity in PlayerPostThink

Last edited by hzqst; 04-22-2015 at 02:29.
hzqst is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 04-22-2015 , 07:45   Re: register_touch and set_pev
Reply With Quote #3

Makes sense, thanks
vitorrossi 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 10:03.


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