Search Unity

[Released] Missile Behaviours

Discussion in 'Assets and Asset Store' started by Sentrigal, Oct 6, 2015.

  1. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    No problem, glad I could help :)
     
  2. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    is it possible to place random launch points say like a silo with multiple launch positions then have them choose a random launch point when press mouse button to launch the next missile?

    and can the targets be selected manually by mouse click or other targeting methods?

    thank you
     
  3. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    No, there is currently no built in way to do that. You'd have to code something like that yourself. Also, I don't think I'll ever include scripts like that by default, because usually scripts like that need heavy modifying to be used in a specific game.
    Either that or the scripts need to be so incredibly generic that you end up with an extremely bloated script, which most people don't like either.

    There is however the Dreadnought script, which should at the very least help you get started. It has an array of transforms and launches a missile from each of them when you press MB1. It's not hard to modify that to make it so that it only launches a single missile from a random transform.

    Selecting a target via cursor is a little more tricky though and depends heavily on how your game works. But just about every person who ever used Unity asked about that at some point, so I'm sure you'll have no trouble finding good answers on Google.

    I'd advise you to try to do this yourself first, because this is the kind of easy enough thing that comes in handy for every script package. But then again, some people just aren't made for coding so let me know if you can't get it to work.
     
  4. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    can the launch position be attached to a moving vehicle like a gunship or aircraft
     
  5. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Sure, I don't see why not. You can use any transform that you want. In your case you'd most likely just make the launch position its on gameobject and make it a child of your gunship.
     
  6. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    thank you for quick reply
     
  7. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    i have got a little problem, i have my enemies in scene all setup working but sometime when a missile hits an enemy that is near other enemys more than just the hit enemy dissapears, the one that is hit shows the explosion but the surrounding enemies just disapear, not sure i have seen this happen in the demo scene but is happening with my own targets, i have double checked that they are setup the same as in the demo1 scene but it keeps happening, if you have an idea why this happens please let me know

    thanks
     
  8. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    That's rather simple, it sound like you are using exactly the same setup I used in the demo scene. The problem with this approach hides inside the script files, in this case in ExplosionDamage.cs:

    And I assume you didn't do that. In that script you'll find this line:
    Code (CSharp):
    1.             Collider[] colliders = Physics.OverlapSphere(transform.position, range, affectedLayers);
    Which essentially says "pick every object on affectedLayers, as long as they are less than range units away". And later in the script these objects are destroyed.

    So if you are using this script, it will just destroy everything in range (30 meters/units by default). And I'd assume that's where your problem is. If you really don't want to, or can't, run your own implementation, you'd probably want to reduce the range variable in that script.
     
  9. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    i had an idea it must have something to do with a range or distance from the explosion, thanks for directing me to the line to change... THANK YOU
     
  10. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi
    I have a simple question, i'm trying to use this instead as of a missile as a semi AI for airplane fighting. I want the airplane to follow another airplane and then switch to a different target when close enough. The issue I'm having is the rotation, if I tell it to follow my target, the missile (which is now an airplane) may be looking upside down or some other weird way that it's not definitely a way an airplane would chase another airplane. Is there a way to improve this?

    Thanks
     
  11. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    That sounds like it's a problem with your model. It might not be oriented correctly for Unity. It's a pretty common issue since most 3D modeling programs out there use a different coordinate system than Unity. You'll have to make sure that the nose of your aircraft is pointing towards the forward axis (the blue arrow). If the model doesn't do that the recommended solution is to make a new, empty, Gameobject and make your model a child of it. That way you can rotate the model so that its nose is pointing forward. Then you simply use the new object as your plane and everything should work.

    That's all assuming that I understood you correctly and that is indeed your problem. If not, let me know.
     
  12. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I mean the rotation of the airplane. I don't mean that the tail is looking towards your target. I mean that the airplane can be upside down or whatever rotation in between, looking towards the target. But an airplane wouldn't be rotated 90 degrees (with a wing up and the other toward the land) for instance, while chasing you on a straight manner. But it would rotate if you turn left/right (one wing up the other down)
     
  13. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Hm. Okay, I get what you mean. But a missile doesn't really care and this is a pack about missiles after all. I'm honestly not sure if that problem is fixable. Since a missile uses vector thrusting and the fins, it can essentially turn which ever way it wants. While an airplane mostly uses its lift to turn. So that's two completely different methods and it seems to me that you can't really simulate one with the other.

    There might be a way to force it upright, but I think that would result in the plane only using the rudder to change direction, which would look a little dumb and is certainly not realistic. I'm afraid you need a whole different approach to simulate an aircraft.

    I'll let you know if I can think of a solution, but I can't promise anything. Again, this is a pack about missiles after all. Perhaps someone else who reads this thread has an idea. Sorry I couldn't be of more help, it's just that this specific case isn't really the intended use of the pack.
     
  14. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Just uploaded version 1.4 for review. The following changes were made:

    - Fixed and improved some tooltips.

    - Added an active target property to the missile controller. This target, if set, will always be the first the missile will try to reach. The normal target will be used if this is null. This makes it easy to, for example, make the missile follow waypoints. As demonstrated by the new script (see below).

    - Added OnTargetChange event to the missile controller. This event can notify any listening scripts whenever the missiles target has been changed.

    - Added OnActiveTargetChange event to the missile controller. This event can notify any listening scripts whenever the missiles active target has been changed.

    - Updated and slightly improved ReadMe file.

    - Added the AltitudeControl script which tries to keep the missile on a predefined altitude until it reaches its target. At which point it will start chasing the target again. It looks something like this:
    http://puu.sh/rovnL/b82e2972a4.jpg
    http://puu.sh/rovqO/f207652d4f.jpg
    The script is still a bit experimental, but functional. So I thought I'd release the update as is to get some feedback.

    - Added a new scene to showcase the new script.

    - Support for Unity versions < 5 has been removed. Since so many people have moved to 5 now and the effort to support both versions is actually pretty high, I decided to drop support for those from now on. Sorry about any inconveniences this might cause.
     
  15. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Version 1.4 is now online!
     
    julianr likes this.
  16. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Version 1.5 is now pending review.
    This is what changed:

    - Since Unity Version 5.5 messed things up a little, there's now a package for this version which should fix that.
    - Fixed some errors and oddities mostly concerning the demo scenes.
    - The guidance scripts are using FixedUpdate again, as it turned out that Update wasn't as stable as my previous tests suggested. It's recommended to use interpolation on the rigidbodies now.
    - Added a new, small guidance script which is intended for unguided missiles. In combination with a few other scripts this allows for new types of missiles.
    - Added a new demo scene to showcase what the new scripts can do.

    As usual, the update should hit the store in about a week.
     
  17. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Turns out it's already out! That's got to be a new record :)
     
  18. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Yet another quick update, just uploaded version 1.5.1 to fix some long standing little issues:

    - All missiles now use rigidbody interpolation. To keep things from looking weird, the camera is now using Update instead of FixedUpdate.
    - The GuidanceDemo scene now instantly spawns a target, instead of waiting for a few seconds.
    - All triggers can now be delayed by a specified amount of seconds. They will only trigger once its object has been alive for longer than that. This should fix the problem with missiles exploding in the silo, while also having some other uses.
    - Added a proximity trigger to the non-carrier missiles. The missiles should now explode when they are too close to the ground. This is a quick fix for the whole ground collision problem.
    - Fixed some warnings: Target colliders are no longer negative scale, as this works differently in Unity 5.5 than it did in Unity 5.0. Further, the ToggleExhaust script now uses the new particle system API, avoiding another few warnings.
    - Removed particle scaling script because it didn't do anything. (Frankly I'm not sure why it was even there :p)

    Please let me know if this broke something else. Managing different sub-versions in Unity 5 is a bit of a pain, since there have been so many API changes between minor versions. But I think I got most of those little warnings now. If not, just post here or drop me a mail :)
     
  19. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    One last quick fix to tidy up version 1.5. Since, for some reason, the labels explaining the control scheme in the demo scenes decided to go haywire again, I quickly fixed that and it should work in every Unity version above 5.0 now. Hopefully...
     
  20. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    Missile Behaviours is currently part of "the biggest sale ever"! It's 25% off and only 2 days left!
     
  21. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    And another sale! This time the weekly themed sale! Get it while it's cheap(er)!
     
    julianr likes this.
  22. jingray

    jingray

    Joined:
    Feb 6, 2015
    Posts:
    53
    How to use for 2D game ?!
     
  23. Sentrigal

    Sentrigal

    Joined:
    Nov 25, 2014
    Posts:
    81
    That very much depends on the implementation of your physics. If you are using Unity's normal 3D rigidbodies and colliders with locked axes, nothing really changes. You just lock the same axis on the missile's rigidbody and everything should work as expected. Frankly, if you don't use the third axis at all, you won't even need to lock the missile's axis.

    If however you are using the 2D variants of Unity's components, things are a lot trickier. It would require either a complete rewrite of almost all scripts, or a hacky workaround. Because Unity opted to differentiate both 3D and 2D components, it's difficult to support both at the same time without having 2 scripts for each.

    The easiest way to achieve this is to just add a 3D-version of a collider to your 2D objects. If they already have a collider, adding a child object with the new collider will work just fine. From there, everything should work about the same as in 3D.

    Hope that helps! If not, let me know, I'm sure there is a decent way to make it work.