Is it possible to make 3D monsters turn around smoothly?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
PixelWAD
Posts: 188
Joined: Sun Jun 10, 2018 7:01 pm

Is it possible to make 3D monsters turn around smoothly?

Post by PixelWAD »

I am using MD3 model files for my monsters. However, when they are chasing the player, they tend to turn 45 degrees spontanously. Is it possible to apply smooth motion to that?
User avatar
Rachael
Posts: 13934
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Rachael »

I don't know if it's possible or not, but if I were to do it I'd just create a second actor that incrementally follows the first so that the movement appears to be smooth.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Graf Zahl »

Rachael wrote:... just ...

Shame on you! :mrgreen: :twisted: :P
User avatar
Rachael
Posts: 13934
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Rachael »

Yeah yeah, I know, that word never does justice to anything. It's just simply overused. So unjustifiably, too. ;)
PixelWAD
Posts: 188
Joined: Sun Jun 10, 2018 7:01 pm

Re: Is it possible to make 3D monsters turn around smoothly?

Post by PixelWAD »

I have added "just" to my actor code and it works perfectly! /s ;)

If you could at least provide me with a mod name that uses such functionality, i would love to have a look.
User avatar
Caligari87
Admin
Posts: 6230
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Caligari87 »

I don't believe there are any existing mods that do this. I did see a tech demo of the technique a while back but I can't recall who or where it was posted.

Here's what I would do: Create your monster as normal, but have it spawn an invisible "chaser" monster when it first spawns. The invisible monster just uses A_Chase to follow the player as normal. Your real monster then, instead of using A_Chase, simply looks at the invisible monster (giving you smooth rotation) and adds velocity in the direction of the invisible monster (giving you smooth movement). For the latter, I recommend a damped-spring formula applied to the appropriate X/Y/Z velocities.

Keep in mind this will require use of pointers and may need some additional manual logic for attack states. If you're not yet comfortable with ZScript this might be a little advanced and will require a bit of tweaking and experimentation to get working properly. There are likely other ways to accomplish this without the invisible chasing monster, but then you'd basically need to write a custom chase function.

8-)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Graf Zahl »

The main problem here will be that even if you get it to look right, monsters can only move in the 8 cardinal directions, unless you write your own monster AI. Writing your own A_Chase which can do more with the angle isn't really that hard: Store the angle, call A_Chase, compare angle and make adjustments.
User avatar
Caligari87
Admin
Posts: 6230
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Is it possible to make 3D monsters turn around smoothly?

Post by Caligari87 »

I suggest this method mainly because it's pretty easy to understand what's happening (at least in my mind) and the code would be a fairly simple extrapolation from the stock behaviors. Obviously if you have the know-how then coding a new chase function is trivial, but in this case the OP probably needs something a little less conceptually abstract. The nice part about my idea is that the looser the "real" monster follows the "chaser", the smoother and more averaged-out the movement becomes. Unfortunately this means it'd also be possible to get stuck or separated from the chaser, in which case some special handling would be necessary.

8-)
Post Reply

Return to “Scripting”