[DIY] "CHF_BEELINE" for A_Chase/A_Wander

Moderator: GZDoom Developers

"CHF_BEELINE" for A_Chase/A_Wander

Postby XLightningStormL » Tue Dec 29, 2020 3:38 am

Basically CHF_BEELINE would simply be a nice alternative to monsters simply zigzagging everywhere (which is possibly part of the reason they're pretty hopeless in pathing)

More or less, unless the player is at a different "horizontal coordinate" (i.e not straight ahead) they will move straight towards the player/target without constantly changing angles (unless they need to)

A feature such as this would be very useful, especially in allowing for better monster pathing/intelligence.
User avatar
XLightningStormL
Former DUSK Wiki Master
 
Joined: 09 May 2016
Discord: XLightningStormL#7461
Twitch ID: XLightmingStormL

Re: "CHF_BEELINE" for A_Chase/A_Wander

Postby Graf Zahl » Tue Dec 29, 2020 3:54 am

'simply' indeed... :?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "CHF_BEELINE" for A_Chase/A_Wander

Postby Marisa Kirisame » Tue Dec 29, 2020 4:06 am

I'd swap that No for a DIY. Excluding DECORATE, this would be fairly easy in ZScript (and has been done before).
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: "CHF_BEELINE" for A_Chase/A_Wander

Postby MartinHowe » Tue Dec 29, 2020 6:42 am

To get the OP started, this is how I did it for the cats. Would also suggest to OP posting their request in the Scripting help thread. Essentially, it consists of using the built-in functions and then correcting the angle bit by bit.

Code: Select allExpand view
    // Customised wander function for the cats; they
    // will navigate to the specified actor, but by
    // default, do so less randomly than as normal.
    //
    // 1. The argument wanderPerson specifies the actor
    //    to wander to; the default is null and means
    //    use the cat's goal.
    // 2. The argument wanderSpeed specifies the speed
    //    with which to wander; the default is zero and
    //    means use the cat's normal speed.
    // 3. The argument wanderDirChance specifies the
    //    probability out of 256 of the actor changing
    //    direction towards wanderPerson while
    //    wandering; this controls how erratically the
    //    cat wanders; the default is 16.
    // 4. The argument wanderDirAngle specifies the
    //    maximum absolute value (zero to 180) of the
    //    angle that should be allowed to exist between
    //    wanderPerson and the cat; the default is 180
    //    (no limit).
    //
    protected virtual void A_BlackCatWander(
        actor wanderPerson = null,
        uint wanderSpeed = 0,
        uint wanderDirChance = 16,
        double wanderDirAngle = 180)
    {
        // Determine who we navigate to
        let navigatePerson = (wanderPerson ? wanderPerson : goal);
        let navigateSpeed = (wanderSpeed ? wanderSpeed : speed);

        // Navigate to the actor
        let oldGoal = goal;
        let oldSpeed = speed;
        let oldTarget = target;
        goal = navigatePerson;
        speed = navigateSpeed;
        if ( (wanderDirAngle < 180) && (Abs(AngleTo(navigatePerson)) > wanderDirAngle))
        {
            target = navigatePerson;
            NewChaseDir();
        }
        target = null;
        A_Wander();
        if (wanderDirChance && (random[BlackCatWander]() < wanderDirChance - 1))
        {
            target = navigatePerson;
            NewChaseDir();
        }
        if ( (wanderDirAngle < 180) && (Abs(AngleTo(navigatePerson)) > wanderDirAngle))
        {
            target = navigatePerson;
            NewChaseDir();
        }
        goal = oldGoal;
        speed = oldSpeed;
        target = oldTarget;
    }
User avatar
MartinHowe
In space, no-one can hear you KILL an ALIEN
 
Joined: 11 Aug 2003
Location: Waveney, United Kingdom

Re: "CHF_BEELINE" for A_Chase/A_Wander

Postby Matt » Tue Dec 29, 2020 3:16 pm

> More or less,
> unless the player is at a different "horizontal coordinate" (i.e not straight ahead)
> (unless they need to)

These are the hard parts.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest