stopping after a MoveToward()

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

beefsack

the authority in beef
Nov 22, 2002
241
0
16
39
Canberra, Australia
beefsack.blogspot.com
i have a NPC controller (subclassing ScriptedController) where i use MoveToward() to move the NPC around. the only thing is i want to be able to stop the pawn before it reaches the destination in the MoveToward() function. does anyone know how to do this?
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
You use a state to tell the NPC to move to a direction, so you get the NPC to a stopping state.

Testing the distance between the NPC and destination is easily done by VSize(NPC.Location - DestinationLocation). Test the VSized value to a certain distance, and just tell the NPC to go to the 'stopping' state.

I think I just made a state without the MoveToward(), and because the NPC is in that state, he will stop moving ... well... I think that is what I did last time when I made NPC type code.
 

beefsack

the authority in beef
Nov 22, 2002
241
0
16
39
Canberra, Australia
beefsack.blogspot.com
k i made separate states. im not actually making scriptedactions if thats what you meant. the npcs still move towards the last destination from roaming when it is in the eating state, so im hoping there is a function or something to stop it still.
Code:
class CowNPCController extends ScriptedController;

var NavigationPoint RoamDestination;
var float ActionTime;

function TakeControlOf(Pawn aPawn)
{
    if ( Pawn != aPawn )
    {
        aPawn.PossessedBy(self);
        Pawn = aPawn;
    }
    GotoState('Roaming');
}

state Roaming
{
    function Timer()
    {
        GotoState('Eating','Begin');
    }

    function SetMoveTarget()
    {
        local Actor NextMoveTarget;
        if( RoamDestination == none ) {
            RoamDestination = FindRandomDest();
        }
        NextMoveTarget = FindPathToward(RoamDestination,false);
        if ( NextMoveTarget == None ) {
            GotoState('Broken');
            return;
        }
        Focus = NextMoveTarget;
        MoveTarget = NextMoveTarget;
        if ( !ActorReachable(MoveTarget) ) {
            MoveTarget = FindPathToward(MoveTarget,false);
            if ( Movetarget == None ) {
                RoamDestination = none;
            }
            if ( Focus == NextMoveTarget )
                Focus = MoveTarget;
        }
    }

    Begin:
        ActionTime = FRand() * 5 + 5;
        SetTimer(ActionTime,false);
        CowNPC(pawn).ChangeAnim('Walk',true);
    StartMoving:
        RoamDestination = none;
        Focus = none;
        Pawn.SetMovementPhysics();
        Pawn.SetWalking(true);
        WaitForLanding();
    KeepMoving:
        SetMoveTarget();
        MoveToward(MoveTarget,,,,Pawn.bIsWalking);
        if (Pawn.ReachedDestination(RoamDestination))
            Goto('StartMoving');
        Goto('KeepMoving');
}

state Eating
{
    function Timer()
    {
        GotoState('Roaming','Begin');
    }
    Begin:
        CowNPC(pawn).ChangeAnim('StartEat',false);
        ActionTime = FRand() * 5 + 5;
        SetTimer(ActionTime,false);
}

defaultproperties
{
}
 

Sir_Brizz

Administrator
Staff member
Feb 3, 2000
26,020
83
48
Snake, do you know why you can't get a unit to move to precise x,y coords with MoveTo?
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
I didn't use MoveTo, I think I used something else. In any case, I'm not to sure why Sir_Brizz, as I've never really delved much into the code. I know that sometimes my NPC's would get to their destination and then move backwards and forwards or something odd, it was really random. But it happened very rarely. I managed to solve it by making the NPC's detect if they are within a certain distance of the destination, and then just making them stop moving so that they were just close enough to the destination anyways.

Otherwise... I have no clue why you can't get a uni to move to precise x,y coords with the MoveTo function.
 

Sir_Brizz

Administrator
Staff member
Feb 3, 2000
26,020
83
48
Well they get close. They stop at the Navigation point I create...but I don't understand...the x,y coords are only off probably 30u's so I figured you could get them to walk right to where you click...unfortunately you can't. all that happened was that they would turn to look at it after they passed it and kep moving and not stopping..

Oh well, they get close enough I suppose.