Announcement

Collapse
No announcement yet.

Calling movetoward twice (ai problem)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    I've now got a system where it keeps looping round and calling MoveTo(enemy.location) and it works ok. It's still not exactly what I want it to do because if the player is moving around a lot, the ai will go to where the player was x seconds ago rather than always walking towards where they are now. I've looked at other ai systems and they seem to use MoveToward in a similar way I am but they don't have problems.

    Thanks for your help.

    Leave a comment:


  • replied
    Yeah I might have to. It might be something to do with how the movetoward function works but it's native so I cant look at it. Also it's a bit akward calling moveto lots of times because it's a latent function so it can only be called in state code and not functions. So I'll have to keep re-entering the state rather than just calling a function every second.

    Leave a comment:


  • replied
    What I was wondering was, was the bot thinking that the enemy hadn't moved since the point when it went into meleeattacking state but I doubt it was happening anyway. Perhaps you could settle with moveto with a smaller timer delay. I don't know how the cpu usuage would change but I can't believe it would be much more.

    Leave a comment:


  • replied
    The enemy is set when the it leaves the idle state. I don't get any accessed nones so I guess the enemy isn't getting set to none. Still I'll check that the enemy doesnt change.

    Leave a comment:


  • replied
    The only thing I can think of is you need to define the "enemy" each time before you do the movetoward, the scriptedcontroller class seems to do that.

    Leave a comment:


  • replied
    The idling state does nothing except checks every second to see if it should go into another state.

    And thanks for the suggestion, I'll do that. There aren't any errors in the log. It moves between states as it should, but it's just that movetoward statement (which is definately being called) that doesn't do anything.

    Leave a comment:


  • replied
    What is the idling state like?

    By the way, I'd recommend you add an = sign between the < and perverted so you cover all bases.

    What does the log say?

    Leave a comment:


  • started a topic Calling movetoward twice (ai problem)

    Calling movetoward twice (ai problem)

    I posted this on the mailing list but I haven't had any help so far so I'll post it here too.

    I'm writing some very basic ai that just needs to move towards an enemy when it sees it and then start attacking. It does this fine but only the first time. For example if you let it reach you then run away, it just stands there and won't start walking towards you again even though the MoveToward function is called again. The class extends scriptedcontroller. This is the relevant code:



    Code:
    state Hunting
    {
         function Timer()
         {
           If(enemy==none)
           {
                   GotoState('idling');//just in case enemy is gone
           }
           else if((VSize(enemy.Location-pawn.location)<Perverted
    (Pawn).MeleeRange) && (FastTrace(enemy.location, Pawn.location)))//if 
    enemy is within melee range and not behind a wall start attacking
           {
                   GotoState('MeleeAttacking');
           }
           else
           {
                   SetTimer(1, false);//if not check again later
           }
         }
    
    begin:
         log("now hunting");
         SetTimer(1, false);
         MoveToward(enemy, enemy,,false);
    }
    
    state MeleeAttacking
    {
         function Timer()
         {
           If(enemy==none)
           {
                   GotoState('idling');//just in case enemy is gone
           }
           else if((VSize(enemy.Location-pawn.location)>Perverted
    (Pawn).MeleeRange) && (FastTrace(enemy.location, Pawn.location)))//if 
    enemy is now out of melee range, hunt them
           {
                   GotoState('hunting');
           }
           else
           {
                   SetTimer(1, false);//if not check again later
           }
         }
    
    
    begin:
         log("now melee attacking");
         Pawn.Acceleration=vect(0,0,0);
         SetTimer(1, false);
    }
    I have checked that it does go back into the hunting state and runs the code at the begin label after enemy moves out of range. But for some reason the MoveToward function has no effect after the first time it's called. Strangely enough using MoveTo works fine but it's not really useful since the enemy will be constantly moving. What could be causing this strange problem?
Working...
X