Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[RELEASED] Fire Arrows - Smart and Performant AI Ballistics With or Without Flame!

Discussion in 'Assets and Asset Store' started by casperjeff, Dec 17, 2013.

  1. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Rain fire death on the enemy with this simple nifty package.



    Designed so NPC or AI can strike out with projectile arrows with perfect (or imperfect) accuracy.

    No coding knowledge required - but complete source code comes with!

    $logo.png

    WebPlayer Demo - watch but can't shoot

    WebPlayer Demo - First Person - shoot away!!

    Arrow will 'stick' in designated objects (even those other than target objects - like terrain or buildings) and child to them - so that hitting an arrow embedded in a zombie's skull will move along with the zombie.

    Optional rigidbody (works fine without - physics calculations are handled manually) allows you to load up a scene with many many arrows without the physics overhead. (NOTE that you must have a rigid body on any objects that an arrow can hit IF you go this route)

    Set your own arrow 'force' to limit range or forcing 'arcing' of arrows to reach targets.

    Predictive targeting available with configurable sampling rate to 'lead' targets (hit a moving target)

    Handles different shooter/target heights. Will arc higher if force is too low to hit target on direct shot

    Random 'inaccuracy' parameters

    Ability to randomly aim for targets in scene or track a specific gameobject.

    Arrow and flame 'destroy' time parameters

    Optional/additional Blue and Green fire arrows.

    Message callbacks to struck targets (to apply damage or whatever)

    Multiple scenes with examples aplenty.

    No use of tags - Targetable and Embedable scripts you can add to any gameobject

    v1.5 additions!!

    .Boom arrows. Arrows that go 'boom' when they hit something. Including explosion effect, sound and physics force
    .Some sound effects - pool of 'woosh' and 'twang' and 'thunk' sounds.
    .Changes to 'random' target selection logic to allow for only targeting those 'in range'.
    .Revamped tracking system for predictive firing to track multiple targets simultaneously
    .Added 'shred' capability to 'explode' simple meshes upon impact.
    .Added first-person launcher capability with both 'straight' and 'perfect' fire methods.

    Asset Store link


     
    Last edited: Jan 2, 2014
  2. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    I posted a webplayer demo:

    https://googledrive.com/host/0B42_t04JD1sYR0lQV1lUa2d4M0k/FireArrowWeb.html

    Also - I found a glitche as I was working on that scene (predictive logic doesn't have time to 'predict' when switching between random targets (works fine with single dedicated target).
    I have a fix queued up but need to get Asset Store approval before I can push it. Will be happy to provide any purchasers with 'fix' if necessary before hand if you PM me.
     
  3. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Plans for version 1.2 (1.1 is minor glitch fix I talked about above)

    .Creating arrow object 'pool' so people who want katrillions of arrows can have them with improved performance
    .Boom arrows. Arrows that go 'boom' when they hit something. Including explosion effect, sound and physics force
    .Some sound effects - pool of 'woosh' and 'twang' and 'thunk' sounds.
    .Changes to 'random' target selection logic to allow for only targeting those 'in range'.
    .Better predictive logic (more expensive computationally- but will be optional)
    .Ability to 'queue' up arrow visually and 'pause' before launching.
     
    Last edited: Dec 19, 2013
  4. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    v1.1 is released - fixed glitch with predictive firing and random target selection (makes it more better). Essentially when 'switching' targets, it will wait a cycle before firing in order to better 'predict' the path of the target.

    Future versions (2.0?) will track multiple targets at the same time - so switching targets will be quick and easy.

    I think that I will work up a new webplayer demo that allows YOU to fire an arrow - based on target closest to center of mouse (or a crosshair system) - still using predictive techniques to land on target.
     
  5. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Last edited: Jan 2, 2014
  6. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Watching boom arrows from the ground....

     
  7. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    And finally....
    A crazy onslaught

    [video=youtube_share;kFj6EYhDgX0]http://youtu.be/kFj6EYhDgX0
     
  8. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Having fun now...
    Exploding (shredding) targets.

    I'm using a very simple script to break the gameobject mesh into component triangles - which works well on unscaled simple cube primitives - totally UNOPTIMIZED and unsuited for complex meshes or scaled objects.

    I HIGHLY recommend THIS asset - it totally rocks for this sort of thing
    http://u3d.as/content/ndp-tools/mesh-explosion/3Fd.

     
  9. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Hoping to have v1.2 done by end of weekend - I also want to throw in a first person demo scene where YOU can shoot and some prefab helpers.
     
  10. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    ...trying to come up with more 'performant' particle effects for those of you targeting mobile....(currently uses tweaked ones from Standard Assets)
     
  11. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Sound effects added and multi-target predictive tracking improvements.
    Also tuned up the FPS control considerably including zoom- allowing for 'perfect' aim or non-perfect (wherever I point at current force).

    In video below, quick-time caused stutters and sound sync issues - it is really much better in reality.
    WATCH WITH SOUND!
     
    Last edited: Dec 21, 2013
  12. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Ok - Cleaning up code and prepping documentation.

    In the meantime, here is a webplayer demo of some of the First Person elements seen in the above video.

    https://googledrive.com/host/0B42_t04JD1sYR0lQV1lUa2d4M0k/FireArrowFPSWeb.html

    (In most browsers, you can 'right click' for perfect-aim shots instead of toggling with P)

    BTW - probably going to bump the price up to $10. Lots more work and features....
    So buy while you can at lower price if you are interested in getting the new updates for cheap.
     
    Last edited: Dec 22, 2013
  13. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    v1.5 coding and documentation is complete. Submitted to Asset Store - waiting on approval

    Changes include:

    .Boom arrows. Arrows that go 'boom' when they hit something. Including explosion effect, sound and physics force
    .Some sound effects - pool of 'woosh' and 'twang' and 'thunk' sounds.
    .Changes to 'random' target selection logic to allow for only targeting those 'in range'.
    .Revamped tracking system for predictive firing to track multiple targets simultaneously
    .Added 'shred' capability to 'explode' simple meshes upon impact.
    .Added first-person launcher capability with both 'straight' and 'perfect' fire methods.
     
    Last edited: Dec 23, 2013
  14. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Revised version 2.0 goals:

    .Creating arrow/explosion object 'pool' so people who want katrillions of arrows can have them with improved performance.
    .Mobile-friendly particle effects (for flame and explosions)
    .Better predicative techniques that detect obstacles in flight path and adjust force/angle as appropriate
    .Better predicative technique that uses iterative simulations to better handle targets moving up/down and forward/back.
    .Realistic looking arrow model(s)
    .Destroy arrows on boom and also make fade instead of abrupt disappear with no boom.
     
    Last edited: Dec 25, 2013
  15. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    As I wait for v1.5 approval by Asset Store, I have been working on more realistic looking arrow models. Be gentle - my first Blender work.

    $4.png $3.png $3.png $1.png
     
  16. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333

    V1.5 is now live!!
     
  17. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    As I have been working on using Fire Arrows in my own came concept, I came across some shortcomings of the ArrowTargetable implementation and have since added a 'side' designation to allow multiple 'entities' with multiple launchers to target other 'sides' but not themselves.
    This will be wrapped up in v 2.0 as well.

    Also - look out for a sister package - Fire Balls! coming soon.......
     
  18. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    This looks cool! How difficult would it be to adapt this to a 2d platformer? Also, is the ai smart enough to know if there are objects in the way? For example if an enemy was behind a wall would they know to shoot over it or just try to shoot through it?
     
  19. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    As far as 2D goes - actually - assuming that all 'units' are on the same Z, I'm pretty sure it would work fine. Are you talking about using the new 2d physics in Unity though? If so - I'll probably have to create a special 2d version.

    As far as obstacles - yeah that's a version 2.0 item. Coming soon!!
     
  20. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Sweet good to here that obstacles are in the pipeline.

    I didn't think about the issues 2d physics would cause. Still this only effects collisions right? When I get to the point in development where I want to add this functionality I'll more than likely pick this up and try to get it working. Based on the videos it really does seem like a cool asset. I can't help but think of ranged combat in Skyrim lol.
     
  21. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    I will also be adding a 'third person click-fire' option - for those that are using a third person type environment and have launcher attached to character and want to 'click-fire' at targets, they can drop solution in place easily.
     
  22. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    ...to the 20+ purchasers of this asset, thanks!!!
    NOTE - I am willing and ready to assist you in integrating this package in your project if you need a hand!!

    Version 2.0 work started tonight......
     
    Last edited: Feb 17, 2014
  23. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Looks like I might have to release a completely separate 2D version
    Too many changes to keep in same package - especially on the 2D physics side,

    The inability for kinematic RigidBody2D to trigger when colliding with non-rigidbody collider absolutely sucks (works different than 3D physics in Unity)

    [video=youtube_share;QMqvvILnvLo]http://youtu.be/QMqvvILnvLo
     
  24. popawheelie

    popawheelie

    Joined:
    May 27, 2013
    Posts:
    23
    If anyone is using AI for Mecanim, you can simply insert the following line under OnTriggerEnter into the ArrowLogic script

    Code (csharp):
    1. void OnTriggerEnter(Collider collision)
    2.         {
    3.            
    4.             collision.gameObject.SendMessage("ApplyAttributeDamage", new object[] { "Health", damage }, SendMessageOptions.DontRequireReceiver);

    Also add a public Int for damage.

    Code (csharp):
    1. public class ArrowLogic : MonoBehaviour
    2.     {
    3. public int damage;
    and finally,

    Code (csharp):
    1. using AISystem;
    at the very top to reference the AI. and it works like a treat.
     
  25. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Thanks for the assist!!
     
  26. macthorman

    macthorman

    Joined:
    Mar 14, 2014
    Posts:
    3
    Hey I started using FireArrows and I absolutely live it :)

    Nevertheless, I have one small issue:
    I imported a new arrow model and bound it on the key #4 in order to select it. This did not cause any issues but when I shoot the arrow it has a wrong angle. It is not facing the direction I am shooting at, it basically has a approx. 90° offset. I tried re-importing the model and changing the rotation in the prefab without any success.

    Do you have an idea how I could overcome this issue?
     
  27. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    I do...ran into the same issue myself when I created the new arrow model for 2.0....
    :)

    when I get home this evening I will take a quick look and see what method I used.
     
  28. macthorman

    macthorman

    Joined:
    Mar 14, 2014
    Posts:
    3
    Thank I am looking forward to your response :)
     
  29. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Hmmm....
    Am I to assume you are using an FPS launcher?
    I compared my most recent (2.0 alpha) code against my 1.5 release and I don't appear to be doing anything funny with the rotation that I can see.
    I am attaching a pic of the orientation of my model so you can see which way is up/right/forward so you can see if you can orient your model the same way.
    If you want to PM me with your model I can try it out see what I can figure out
    or I can PM you an alpha version of 2.0 with MY new model if you'd like. $1.jpg
     
    Last edited: Mar 18, 2014
  30. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Line 149(ish) of FPSArrowLauncher.cs
    Code (csharp):
    1.  
    2. GameObject a = Instantiate (arrow, transform.position + transform.forward * 1.0f, Quaternion.LookRotation (heading)) as GameObject;
    3.  
    Looks as if I expect the prefab to have forward pointing a certain way - you could rotate that prefab until the cows come home and it won't matter.
    Grumble.
    Normally in Unity, you would simply create an empty parent for your arrow and then rotate your arrow child accordingly (people run in this model rotation thing all the time). Off the top of my head, however, not sure how that will effect my code.
    If you can rotate your original model pre-import (from a modeling tool), you could be good to go.
    Otherwise, send me your model and I will figure out how best to incorporate.
    I will try to make changes to v2.0 to better compensate for this.
     
  31. macthorman

    macthorman

    Joined:
    Mar 14, 2014
    Posts:
    3
    Ok, thanks for the answer. I had to play around a little bit but changing the transformation/ rotation in blender solved the issue. I had to rotate the model to Z=-90° which basically means that the arrow is pointing to the left side.
     
  32. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hi is this asset still being supported?

    I would like to know what the performance is like on mobile? Thank you
     
  33. ahmetc

    ahmetc

    Joined:
    May 5, 2014
    Posts:
    5
    Hi. Would be interested on that as well. Anyone tested the mobile performance or if it is any good on mobile? Will buy asset if yes. Thanks!
     
  34. ATeam_Production

    ATeam_Production

    Joined:
    Nov 23, 2013
    Posts:
    82
    Hi. I would like to know the performance on mobile too. Thank you.
     
  35. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Howdy all - I have not done much performance testing on mobile - except the basic path algorithm.
    I'll whip up a mobile experiment with the package this weekend and report back!
     
    ATeam_Production likes this.
  36. ATeam_Production

    ATeam_Production

    Joined:
    Nov 23, 2013
    Posts:
    82
    Nice to read that! Thank you Jeff.
     
  37. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Just did a bunch of tests on IOS (on iPhone6+) running IOS 9.2.1 - everything ran flawlessly and quite performant.
    I'll try to borrow an android device later in the weekend and see how that goes...but I don't expect anything different.
    (this was compiled using Unity v5.3.2f1)
     
  38. ATeam_Production

    ATeam_Production

    Joined:
    Nov 23, 2013
    Posts:
    82
    I have it!!! I will certainly try this week-end. I see that you upload the asset, nice! I wil let you know what I'm able to do with it. I have a Spartan Boat Battle to do for a mobile game ... I think that your work will help me a lot!
     
  39. ahmetc

    ahmetc

    Joined:
    May 5, 2014
    Posts:
    5
    wow didnt expect any neews here :) i bought ur asset like a year ago and actually i did test it on my android galaxy note phone and LG G2. Both ran it perfectly but the touch controls of course were not fully tested yet. still i would love to see some tutorial or asset with a bow shooting in FPS view. i mean not only the animation, actually the shooting scripted with hitting (including the arrow flying from bow to target). did not find such tutorial or asset yet but i didnt really check store for a year now.
     
  40. Howzer

    Howzer

    Joined:
    Oct 17, 2012
    Posts:
    13
    Hi, suppose a character had an autolauncher attached to hand bone but also had embeddable and targetable attached. How do I get the autolauncher to stop targeting itself in some situations when the hand is moving?
     
  41. TonanBora

    TonanBora

    Joined:
    Feb 4, 2013
    Posts:
    493
    @casperjeff
    Hello!
    I bought your arrow asset, and was looking through the documentation, and the code, and I have a few tips for you.
    In the docs, you mention Force (in the AutomatedArrowLauncher script) is "clamped" between 5, and 75, yet I can input any float value I want. This is also true for the accuracy variable (except the range is from 1, 100).

    So, I highly suggest that you use the Range Attribute for those variables, like so:

    Code (CSharp):
    1. [Range(5, 75)] // The Range attribute clamps this variable between the given range.
    2. public float force = 5;
    3.  
    4. [Range(1, 100)]
    5. public int accuracy = 95;
    This also has the neat effect of creating a slider in the inspector for the variable. :)
    For error prevention reasons, I still suggest you keep the Math.clamp code in the start function.

    In addition, I highly suggest you keep variables private, and create setters and getters for them if outside sources needs to access these variables. If you do this, you can put Clamp code into the setter for accuracy and force to prevent them from getting set to a number outside their range. If you want to make it so they can be set in the inspector, add the [SerializedField] attribute to them.
     
    Last edited: Jun 29, 2016
  42. karmik

    karmik

    Joined:
    Oct 8, 2014
    Posts:
    124
    Hi @casperjeff

    Planing to use your arrow in my third person game to let the player shhot arrows on button click or click on enemy to shoot.

    Will that be possible?
    Can you help me integrate pls?