Search Unity

Pre-made AI Systems for a Freelancer style 3D Space Shooter

Discussion in 'General Discussion' started by Sasstraliss, Mar 27, 2013.

  1. Sasstraliss

    Sasstraliss

    Joined:
    Feb 24, 2013
    Posts:
    10
    I'm creating a 3D space shooter, similar to Freelancer in it's gameplay and fighting style.

    I'm at the point of drafting and doing some basic implementations of AI enemies for the player to fight.

    There seems to be a few asset-store AI systems for waypoints, object avoiding, etc. I'm curious which would best suit type of AI I'd need for my game.

    Being a 3D space shooter, the AI has to navigate in 3 dimensions, and can't make use of a NavMesh (given my understanding of it).

    I've considered the use of multiple raycasts per enemy ship, so ensure no object collisions, however this is no doubt expensive.

    Essentially, I'd like the enemies to patrol around systematically (perhaps in formation), and engage a player that's within range, but constantly move in a way that isn't directly towards the player, but a flanking sort of movement.

    As it stands now, my AI essentially moves directly towards the player, and fires when a direct LOS is achieved. It's very primitive, and I'm curious if the pre-made AI systems would benefit. If so, which would suit best?

    Thanks in advance.
     
  2. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    Instead of using multiple raycasts, couldn't you instead use a raysphere?
     
  3. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
  4. Sasstraliss

    Sasstraliss

    Joined:
    Feb 24, 2013
    Posts:
    10
    Sorry to bump this old thread.

    I've read those articles Kinos, and they were helpful. It doesn't cover what I need however.

    At the moment, I have a setup in which an enemy ship fire a ray in front of it. If that ray hits anything the ships new target is set to a point around the obstacle, and the ship steers to the new target. When it reaches the new target, the object will obviously not be in-front of it and it then resets its new target to the player again. This cycle repeats everytime something intersects the ships forward raycast.

    The system is certainly not intelligent. The ship navigation avoids objects but it's not efficient in avoiding them. I don't mean computing efficiency, I mean it doesn't look fluid. The system would struggle with moving obstacles for example.

    Now there are many systems both in the asset store and integrated into Unity Pro (NavMesh). Those systems often use grids with A* pathfinding, etc.

    I can't use them. These ships need to navigate in 3 dimensions (it's space) and avoid dynamically moving objects.

    Ontop of the basic navigation (object avoidance) system I'd like to pile on proper combat navigation (where the enemy flies in order to flank and surround the player, etc). I'm sure I can work that out, but having a more solid system would help.

    Are there pre-made systems for this? I haven't found any that cater to my needs, due to the dimensions I'm working in.

    For those of you who played Freelancer, the AI was terrific (for its time) and I'd like to create something at least a fraction as feature filled.
     
  5. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
    I would also recommend implementing steering behaviors. (Boids)
    You will need to understand the individual steering behaviors once you do.
    You will need to understand on how to apply them on top of each other.

    I would recommend a weighting parameter, that way you can influence the strength of the behaviors.
    You could try implementing them with a trigger collider or using a flat array.

    Steering behaviors are very powerful once you understand and master them.

    Here is more reading materials:
    http://www.red3d.com/cwr/boids/
    http://www.red3d.com/cwr/steer/

    This might be a complete solution (did not test):
    http://arges-systems.com/blog/2009/07/08/unitysteer-steering-components-for-unity/

    Fun Fact:
    The world in freelancer is built on a 2D Plane.
     
    Last edited: May 4, 2013
  6. Sasstraliss

    Sasstraliss

    Joined:
    Feb 24, 2013
    Posts:
    10
    Thanks for the resources. Is there anything for obstacle avoidance in 3D?

    Also, the ships in freelancer still navigated in 3D fairly well.
     
  7. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    A basic combination of trigger volumes and maybe raycasts should do the job.

    Setup up a collision trigger layer with say a sphere collider on each ship/object and when they touch have the AI ships maneuver and ensure they don't collide.

    You may need to increase and decrease the size of the colliders based on the speed/maneuverability of the ships.

    This should also work for missile avoidance routines.