Advanced AI

0 favourites
  • 2 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • So Im trying to make some AI using line of sight and Rex's MoveTo behaviour. Got it working great, my enemy will see, move to the player and stop to attack. I just would like to figure out a few thing, setting the enemy's rotation to the direction its moving, currently, I have it set to if CanSee - every 0.1 seconds - rotate towards player, which works but.. does weird things sometimes, and doesn't look quite right. Ive tried other methods and not found one that works, I can set the angle to the moving angle, for some reason thats not an expression.

    The other thing, is the AI part. I want my enemy to after reaching the player, wait a second and move to a different place around the player. I could not find a way to do this either. If i can make the enemy touch the player, move to a random position close to the player, and then back to the player that would work. Let me know if you want to see the capx, I have two addons, rex's MoveTo, and rex's PushOutSolids.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • First issue - change your event to this:

    if Enemy has LineOfSight to player -> Set Enemy angle to Anglelerp(Enemy.Angle, angle(Enemy.X, Enemy.Y, Player.X,Player.Y), dt*4)

    Number "4" here is the speed of rotation.

    Second issue - after 1 second you can move your enemy to this position:

    MoveTo ->

    X=Player.X + choose(-1,1)*random(20,50)

    Y=Player.Y + choose(-1,1)*random(20,50)

    This will simply move the enemy to a random point around the player within 50px, but not closer than 20px.

    Or, if MoveTo behavior has "Move at angle" action, you can do something like this:

    Set dist=distance(Enemy.X, Enemy.Y, Player.X,Player.Y)*random(0.2,0.5)

    Move (dist) at Angle (angle(Enemy.X, Enemy.Y, Player.X,Player.Y) + choose(-1,1)*random(30,60))

    These formulas are just off top of my head, may not work very well.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)