Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
raigan

question about monster movement

Recommended Posts

hi,

Sorry if this is a noob question, but I've been digging through the source trying to understand how things work, and I have a question about how monster movement is implemented: specifically, is it the true that monsters generally only actually move every 3 ticks?!

 

(If so I'm a bit shocked, since monster movement doesn't look as step-y and un-smooth as I would assume it should if they're actually only animating at ~13hz (40hz/3))

 

From what I can see, P_MobjThinker() moves things according to their momentum, and then triggers state changes/actions.

However, unless I'm mistaken, momentum is only used for missile movement, player movement, and to "shove" objects (ie moving things a bit when they take damage); regular locomotion of monsters through the world doesn't involve momx/momy.

 

Instead, the actual walking movement of a monster through the world seems to be driven by A_Chase (which uses P_TryWalk, which uses P_Move, which uses P_TryMove, which actually changes the x,y values of the object using the vector movedir*speed.)

 

But since, AFAICT, action functions are only triggered on the first tick of a given state, this means that monsters with A_Chase states every 3 ticks are stationary for 2/3 ticks... is that correct??

 

Anyway, sorry if this is a silly question, I'm just trying to figure out if I've misunderstood something or if movement really is only happening at 13hz.

 

Cheers,

Raigan

Share this post


Link to post

That's a great question and you're absolutely right on all counts. Monsters only move once per A_Chase cycle. The point, I believe, is to spread the load of monster artificial intelligence over multiple gametics (world updates). Note when P_SpawnMobj creates an actor its first state update is given a random delay. This means only a fraction of the map's monster population is being passed through A_Look or A_Chase per display frame. This lowers the CPU load and helps to keep the framerate reasonable on a 386.

The amazing part is how your brain fills in the gaps and makes it all seem smooth. I think this stops happening if you use uncapped framerate in a source port. With the rest of the game using interpolation to update the screen at 60+ frames per second, the monster stepping is thrown into sharp relief. One reason to remain at 35 :).
 

Share this post


Link to post

Thanks so much, that makes sense -- that's a pretty cool trick, do 1/3 of the work each frame. (For some reason I mis-remembered that Doom ran at 40hz, since it's actually 35hz that means movement only happens at less than 12hz!)

 

I have a follow-up question about the randomness you mentioned: I can't actually find where that happens, could you point me towards it?

 

In P_SpawnMobj I see this this code: mobj->lastlook = P_Random () % MAXPLAYERS;

 

That seems to be the only invocation of P_Random(); however AFAICT this won't introduce a delay (since P_LookForPlayers() will scan across all players checking if lastlook is valid (and updating it if not)). Or am I mistaken?

Share this post


Link to post

Sorry, I misremembered, I should have checked. It is actually in P_SpawnMapThing:

if (mobj->tics > 0)
    mobj->tics = 1 + (P_Random () % mobj->tics);

 

Share this post


Link to post

12 frames per second is definitely enough for movement to appear smooth. Most animation is done at that rate, old anime is often done at less than that, and most of the time you can't even notice. This is part of the reason film people swear by 24 fps, because it's much more than enough, and 48 or 60 fps makes movement look unnaturally smooth and edges of moving objects way too sharp (no motion blur), which is unpleasant to look at compared to 24 fps.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×