Results 1 to 5 of 5
  1. #1
    Skaarj
    Join Date
    Mar 2012
    Location
    Watkins Glen, NY
    Posts
    21

    Question Tower Defense AI

    Hey everybody!

    I'm working on a Tower Defense game with my team, and I've been trying to get bots to path through the level to a goal line, where they make a noise and are destroyed.

    I'm in prototyping phase, and I have them running in a squiggly line through the level, using Kismet Move-tos to work from one path node to another.

    However, they bunch up at the first or second nodes, and sometimes one will skip ahead to much farther down the line of nodes and take a short cut, and then a few others will jostle for positions at various nodes; usually, only one will finally make his way through the whole system and trigger the goal.
    I personally have tried:

    • Using Pylons (I set up four to cover the map, made sure they didn't overlap, and tried using both the sequence of path nodes and just telling them to try to find the goal zone)
    • Using different AI controllers (None, UT, UDK, and basic AI) but they all behave similarly or poorer than UTBot
    • Moving the nodes around to clarify the lines of sight but no luck there
    • Creating 7 empty variables (one for each bot) instead of just one, but no luck


    I also took a look at the script for the Dungeon Defenders UDKRTSAIController, which apparently can find its way using just a pylons-based navmesh, but am not sure I get it. It extends AIController, and included this helpful-looking code:
    Code:
    function MoveToPoint(Vector MovePoint, optional bool DisableAutomation)
    {
        // If disabling automation, clear the WhatToDo timer
        if (DisableAutomation && IsTimerActive(NameOf(WhatToDo)))
        {
            ClearTimer(NameOf(WhatToDo));
        }
    
        // Move to a point in the world
        Destination = MovePoint;   
        FocusSpot = MovePoint;
        SetDestinationPosition(Destination);
        Resource = None;
    
        if (!HasReachedPoint(Destination))
        {
            GotoState('MovingToPoint');
        }
    }
    But I'm not sure how that'll be helpful, especially because the UDKRTSAIController is 1,439 lines long. The Developer also includes some additional code in his diary, about which he says "These few bits of code are essentially all it takes for an AI Controller to walk through navigation results from a Nav Mesh." The few bits of code follow:

    Code:
    function InitNavigationHandle()
    {
       if( NavigationHandleClass != None && NavigationHandle == none )
          NavigationHandle = new(self) class'NavigationHandle';
    }
    
    event vector GeneratePathToActor( Actor Goal, optional float WithinDistance, optional bool bAllowPartialPath )
    {
       local vector NextDest;
    
       //set our return value equal to our destination Actor’s Location.
       //In case it’s directly reachable or pathfinding fails, we’ll just return this.
    
       NextDest = Goal.Location;
    
       if ( NavigationHandle == None )
          InitNavigationHandle();
    
       //if the Actor isn’t directly reachable, then try to find the next navigation point towards it.
       //Otherwise we’ll just return its location to go there directly.
    
       if(!NavActorReachable(Goal))
       {
       class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle, Goal );
       class'NavMeshGoal_At'.static.AtActor( NavigationHandle, Goal, WithinDistance, true );
       if ( NavigationHandle.FindPath() )
          NavigationHandle.GetNextMoveLocation(NextDest, 60);
       }
    
       NavigationHandle.ClearConstraints();
    
       return NextDest;
    }
    It would be great if we could drop a pawn into a simple navmesh and tell them to find the goal line and go there, but I'm not 100% sure how this would be accomplished.

    Can anyone offer any help? I am sadly not a great programmer.

  2. #2
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Posts
    91

    Default

    you need use MoveTo or MoveToward latent function to achieve it.

  3. #3
    MSgt. Shooter Person
    Join Date
    Apr 2012
    Posts
    73

    Default

    This belongs in the Programming section, no doubt you'll find more help in there
    Anyway, i'll help you.
    Code:
    class TDBot extends UTBot;
    var Vector TargetDestination // If you want to use points
    var Actor Target // If you want to use Actors
    var Vector NextMoveDest // Used to move the pawn toward the destination
    function InitNavigationHandle()
    {
       if( NavigationHandleClass != None && NavigationHandle == none )
          NavigationHandle = new(self) class'NavigationHandle';
    }
    
    event vector GenerateVectPathToActor( Actor Goal, optional float WithinDistance, optional bool bAllowPartialPath )
    {
       local vector NextDest;
    
       //set our return value equal to our destination Actor’s Location.
       //In case it’s directly reachable or pathfinding fails, we’ll just return this.
    
       NextDest = Goal.Location;
    
       if ( NavigationHandle == None )
          InitNavigationHandle();
    
       //if the Actor isn’t directly reachable, then try to find the next navigation point towards it.
       //Otherwise we’ll just return its location to go there directly.
    
       if(!NavigationHandle.ActorReachable(Goal))
       {
       class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle, Goal );
       class'NavMeshGoal_At'.static.AtActor( NavigationHandle, Goal, WithinDistance, true );
       if ( NavigationHandle.FindPath() )
          NavigationHandle.GetNextMoveLocation(NextDest, 60);
       }
    
       NavigationHandle.ClearConstraints();
    
       return NextDest;
    }
    
    State MovingToPoint
    {
    Begin:
    NextMoveDest = GenerateVectPathToActor(TargetActor);
    MoveTo(NextMoveDest,none,30,false);
    if(VSize(TargetActor.Location - Pawn.Location) < 35) //Change value for closer or further to finally kill self
    {
    //Kill self here
    }
    else
    {
    goto 'Begin';
    }
    }
    Last edited by Eternal Dusk; 05-09-2012 at 11:15 AM.

  4. #4
    MSgt. Shooter Person
    Join Date
    Apr 2012
    Posts
    73

    Default

    If you any problems, tell me. I'm happy to help I'm at school currently as well so I don't have nFringe intellisense to help me :P

  5. #5
    Skaarj
    Join Date
    Mar 2012
    Location
    Watkins Glen, NY
    Posts
    21

    Default

    That looks like an awesome solution, but I'm dense and have a question or two:

    Question 1: How do I assign a target in the map to be the thing that it goes to?
    Question 2: Will this allow the pawn to navigate toward the destination, even if his path becomes suddenly obstructed by an interp actor or something of the like?


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.