Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dylan760 · Nov 12, 2014 at 10:26 AM · steeringchangingunitysteerenemy-ai

UnitySteer SteerForPursuit: How do you Change quarry After the current quarry gets destroyed

i am using a free asset called unity steer for a space ship game and i want the ally ship to change quarry (target) after the current quarry is destroyed. i want the quarry to be changed to a game object with the tag "Enemy", but Quarry isnt a Gameobject variable so i cant do it directly.

this is the full code from the ally pursuit script

 #define ANNOTATE_PURSUIT
 using UnityEngine;
 
 namespace UnitySteer.Behaviors
 {
     /// <summary>
     /// Steers a vehicle to pursue another one
     /// </summary>
     [AddComponentMenu("UnitySteer/Steer/... for Pursuit Ene")]
     public class SteerForPursuitEne : Steering
     {
         #region Private fields
 
         /// <summary>
         /// A distance at which we are 'close enough' to stop pursuing
         /// </summary>
         /// <remarks>
         /// Notice that this is different from the vehicle's arrival radius,
         /// since we may want to be able to have an attack distance that is
         /// different from the radius used when moving to a point.
         /// </remarks>
         [SerializeField] private float _acceptableDistance;
 
         /// <summary>
         /// Should the vehicle consider its own speed when approaching the quarry?
         /// </summary>
         [SerializeField] private bool _slowDownOnApproach;
 
         [SerializeField] private DetectableObject _quarry;
 
         [SerializeField] private float _maxPredictionTime = 5;
 
         #endregion
 
         #region Public properties
 
         public float AcceptableDistance
         {
             get { return _acceptableDistance; }
             set { _acceptableDistance = value; }
         }
 
         /// <summary>
         /// Maximum time to look ahead for the prediction calculation
         /// </summary>
         public float MaxPredictionTime
         {
             get { return _maxPredictionTime; }
             set { _maxPredictionTime = value; }
         }
 
         /// <summary>
         /// Target being pursued
         /// </summary>
         /// <remarks>When set, it will clear the flag that indicates we've already reported that we arrived</remarks>
         public DetectableObject Quarry
         {
             get { return _quarry; }
             set
             {
                 if (_quarry != value)
                 {
                     ReportedArrival = false;
                     _quarry = value;
                 }
             }
         }
 
         #endregion
 
         protected override Vector3 CalculateForce()
         {
             if (_quarry == null)
             {
                 enabled = false;
                 return Vector3.zero;
             }
 
             var force = Vector3.zero;
             var offset = _quarry.Position - Vehicle.Position;
             var distance = offset.magnitude;
             var radius = Vehicle.Radius + _quarry.Radius + _acceptableDistance;
 
             if (!(distance > radius)) return force;
 
             var unitOffset = offset / distance;
 
             // how parallel are the paths of "this" and the quarry
             // (1 means parallel, 0 is pependicular, -1 is anti-parallel)
             var parallelness = Vector3.Dot(transform.forward, _quarry.transform.forward);
 
             // how "forward" is the direction to the quarry
             // (1 means dead ahead, 0 is directly to the side, -1 is straight back)
             var forwardness = Vector3.Dot(transform.forward, unitOffset);
 
             var directTravelTime = distance / Vehicle.Speed;
             // While we could parametrize this value, if we care about forward/backwards
             // these values are appropriate enough.
             var f = OpenSteerUtility.IntervalComparison(forwardness, -0.707f, 0.707f);
             var p = OpenSteerUtility.IntervalComparison(parallelness, -0.707f, 0.707f);
 
             float timeFactor = 0; // to be filled in below
 
             // Break the pursuit into nine cases, the cross product of the
             // quarry being [ahead, aside, or behind] us and heading
             // [parallel, perpendicular, or anti-parallel] to us.
             switch (f)
             {
                 case +1:
                     switch (p)
                     {
                         case +1: // ahead, parallel
                             timeFactor = 4;
                             break;
                         case 0: // ahead, perpendicular
                             timeFactor = 1.8f;
                             break;
                         case -1: // ahead, anti-parallel
                             timeFactor = 0.85f;
                             break;
                     }
                     break;
                 case 0:
                     switch (p)
                     {
                         case +1: // aside, parallel
                             timeFactor = 1;
                             break;
                         case 0: // aside, perpendicular
                             timeFactor = 0.8f;
                             break;
                         case -1: // aside, anti-parallel
                             timeFactor = 4;
                             break;
                     }
                     break;
                 case -1:
                     switch (p)
                     {
                         case +1: // behind, parallel
                             timeFactor = 0.5f;
                             break;
                         case 0: // behind, perpendicular
                             timeFactor = 2;
                             break;
                         case -1: // behind, anti-parallel
                             timeFactor = 2;
                             break;
                     }
                     break;
             }
 
             // estimated time until intercept of quarry
             var et = directTravelTime * timeFactor;
             var etl = (et > _maxPredictionTime) ? _maxPredictionTime : et;
 
             // estimated position of quarry at intercept
             var target = _quarry.PredictFuturePosition(etl);
 
             force = Vehicle.GetSeekVector(target, _slowDownOnApproach);
 
 #if ANNOTATE_PURSUIT
             Debug.DrawRay(Vehicle.Position, force, Color.blue);
             Debug.DrawLine(Quarry.Position, target, Color.cyan);
             Debug.DrawRay(target, Vector3.up * 4, Color.cyan);
 #endif
 
             return force;
         }
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dylan760 · Nov 12, 2014 at 07:22 AM 0
Share

Theres a script called DetectableObject (so i guess its derived from monobehviour) and if its attached to a game object it is targetable.

the Game objects that contains vehicle scripts are also targetable

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Unity Steer - Setting Quarry in Steer for Pursuit problem 1 Answer

UnitySteer obstacle avoidance on non Spherical Objects 1 Answer

Unitysteer - Rigidbody with gravity stops steering 2 Answers

UnitySteer - Steering around an sphere 0 Answers

Robot Simulation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges