programmatically changing origin and angles Created 5 years ago2019-02-16 06:49:33 UTC by tschumann tschumann

Created 5 years ago2019-02-16 06:49:33 UTC by tschumann tschumann

Posted 5 years ago2019-02-16 06:49:33 UTC Post #342034
I've got a class that inherits from CBaseAnimating and it seems like changes to pev->origin and pev->angles don't cause any changes to the rendered model (but traces do seem to respect the new position).
If I inherit from CBaseMonster the problem goes away - I've narrowed the cause down to CBaseAnimating :: StudioFrameAdvance (which gets called as part of CBaseMonster's main think method). Specifically, the line pev->animtime = gpGlobals->time; seems to cause the rendered model to update. Doing this manually seems to produce jittery results that reverse themselves after a second or so. pev->animtime += 1; seems to sync the changes without any jitter, although changing another attribute causes a delayed change of the previous attribute before updating the new attribute.

Anyway, I've wasted a lot of an afternoon trying to figure out what the problem was. If there's a better solution (one that doesn't cause a delayed change when changing a new attribute) I'd be interested. Any ideas why changing the animation time is needed too? Changing these attributes on sprite-based entities works fine I think.
Posted 5 years ago2019-02-16 09:49:25 UTC Post #342035
Are you trying to change the origin of bullet tracers and shell origin?
Posted 5 years ago2019-02-16 10:07:01 UTC Post #342036
Show the code you're using.
Posted 5 years ago2019-02-17 01:46:09 UTC Post #342046
I'm getting a CBaseEntity using FindEntityForward then doing pForward->pev->origin.x += 1; or pForward->pev->angles.x += 1; or whatever. If I do pForward->pev->animtime += 1; right after that I see the entity move without any jitter but it looks like the updates get queued i.e. if I start updating a new field it changes the previous field first one more time.
If the entity inherits from CBaseAnimating it needs the pev->animtime hack but if I inherit from CBaseMonster then the calls to StudioFrameAdvance make it work.
Posted 5 years ago2019-02-17 14:26:39 UTC Post #342048
You should always use UTIL_SetOrigin when changing an entity's origin, unless the origin variable is being used for storage (some entities do this, but it's a bad idea).

StudioFrameAdvance will trickle down into movement update logic which applies the animation movement to the NPC so the origin variable will be updated.

Changing pev->angles should work regardless though. Make sure nothing is resetting the angles elsewhere.
Posted 5 years ago2019-03-01 11:39:09 UTC Post #342102
I was calling UTIL_SetOrigin but that didn't help.
Playing around with it some more and it still seemed to happen... sometimes. I don't think anything is resetting stuff as it mostly works.
More experimenting required.
You must be logged in to post a response.