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
1
Question by 1337GameDev · Jan 23, 2012 at 11:28 PM · lookatprojectiletarget

Missile Homing and correcting the "dead zone"

I have a similar problem to this: http://gamedev.stackexchange.com/questions/17313/how-to-prevent-homing-entities-from-orbiting-their-targets

But i am unsure how to implement those, most game is see is where they slow down the moving object to increase its steering potential (decreasing the shadow region where it cant go to due to steer limits).

How would i detect it entering this orbit and then just decrease its velocity? (i am using the nonphysics approach for homing and using LookAt method.

Any ideas?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by aldonaletto · Jan 24, 2012 at 11:05 AM

When the missile is orbiting a target, the angle between its current velocity and the vector missile->target is near to 90 degrees - the problem here is how to get the missile velocity vector, since you're not using physics. If you don't know the velocity vector, it can be calculated in Update:

var target: Transform; // the target transform private var lastPos: Vector3; // used to calculate the velocity vector

function Start(){ lastPos = transform.position; }

function Update(){ // calculate the velocity vector: var vel: Vector3 = (transform.position - lastPos)/Time.deltaTime; lastPos = transform.position; // update lastPos // get the missile->target vector: var tgtDir: Vector3 = target.position - transform.position; var angle = Vector3.Angle(vel, tgtDir); if (angle > 70 && angle < 110){ // may be orbiting target: reduce // the missile velocity } }

Comment
Add comment · Show 4 · Share
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 1337GameDev · Jan 24, 2012 at 02:18 PM 0
Share

Why use lastpos only in start? What if I am facing target, and then missile orbits parallel to this vector? Then it doesn't work. Can't I use a deltaposition? (store position ever update iteration)? I do like your answer, but i don't really know for sure, is there some way to figure out if target is within the "shadow region" somehow? Any way to use cross product to deter$$anonymous$$e missile perpendicular vector, and see if this vector seems to always point to target? How would I see if it is doing that?

avatar image Bunny83 · Jan 24, 2012 at 02:50 PM 1
Share

The name lastpos should be obvious always the last position. It's more a prove of concept here. You have to set the last position after you moved your missile. Use either LateUpdate or do it after you moved it in your missile code.

avatar image aldonaletto · Jan 24, 2012 at 06:56 PM 1
Share

$$anonymous$$ea culpa! I forgot to update lastPos in the code (I fixed my answer).
lastPos is used to calculate the delta position between updates; it's being divided by deltaTime to get the velocity, but this division can be omitted - only the direction matters.
$$anonymous$$y first idea was to use the dot product, but Angle is easier and more intuitive (both vectors should be normalized to get a consistent dot product).
The idea is to reduce the missile velocity when it is passing by the target, what could create an spiral. If you want a better behaviour, narrow the angles (>60 and < 80, for instance).

avatar image 1337GameDev · Jan 24, 2012 at 07:54 PM 0
Share

Yup I got it after it was mentioned above. I just thought I missed something. This seems to work great, I assumed it would reduce the speed in odd circumstances, but it didn't, thanks for the help! I'll use this on other parts of game code too :)

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a projectile arc and always hit a moving target? 4 Answers

lookAt on Y axis only 1 Answer

"look at target" problem 1 Answer

GameObject look at velocity (not rigidbody) 0 Answers

Trying to destroy a projectile and "teleport" to another area of the screen when it hits a target. 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