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 wijesijp · Feb 06, 2014 at 11:56 AM · movementrocket

How to create a heat seeker

I am making a 2D tower defense game with unity. I have seen heat seeker type rockets in Kindom Rush that moves around the screen and goes to the target. Really nice effect.

Can anyone give me some direction how to create this type of movement?

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

2 Replies

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

Answer by robertbu · Feb 06, 2014 at 05:18 PM

It appears from the brief video glimpses, that the projectile heads straight up, levels off at some arbitrary vector than seeks the target. Here is a bit of sample code. To test start with a new scene. Put this script on a game object with a Rigidbody component, with gravity turned off, and with a 'y' value of zero. In the inspector initialize 'target' to another object in the scene and hit play:

 #pragma strict
 
 var target : Transform;
 var upHeight = 0.5;
 var turnSpeed = 100.0; // Degrees per second
 
 private var initialDirection = Vector3.forward;
 private var velocity = 3.0;
 
 function Start() {
     initialDirection = Quaternion.AngleAxis(Random.Range(0.0, 360.0), Vector3.up) * initialDirection;
     transform.rotation = Quaternion.LookRotation(Vector3.up);
     rigidbody.velocity = Vector3.up * velocity;
     
     // Head up for a set distance
     while (transform.position.y < upHeight) {
         yield;
     }
     
     // Level off to an arbitrary vector
     var q = Quaternion.LookRotation(initialDirection);
     while (transform.rotation != q) {
         transform.rotation = Quaternion.RotateTowards(transform.rotation, q, Time.deltaTime * turnSpeed);
         rigidbody.velocity = transform.forward * velocity;
         yield; 
     }
     
     // Seek the target
     q = Quaternion.LookRotation(target.position - transform.position);
     while (transform.rotation != q) {
         rigidbody.velocity = transform.forward * velocity;
         transform.rotation = Quaternion.RotateTowards(transform.rotation, q, Time.deltaTime * turnSpeed);
         q = Quaternion.LookRotation(target.position - transform.position);
         yield; 
     }    
 }
 
 function OnCollisionEnter() {
     Debug.Log("Boom");
     Destroy(gameObject);
 }

Note this code assumes an object in which the front is facing positive 'z' when the rotation is (0,0,0) (or an object like a sphere that has no explicit front).

Comment
Add comment · Show 1 · 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 wijesijp · Mar 25, 2014 at 05:03 AM 0
Share

Not exactly what i was looking for, but this is really interesting. Thanks

avatar image
2

Answer by fafase · Feb 06, 2014 at 12:26 PM

Hey could not really find the rocket you are mentioning in Kingdom Rush. Nonetheless we can try.

So first your rocket has a starting point, either a rocket launcher or outside the screen. Then it has a target point. For now let's consider the target point to be where you clicked.

So we need to move the object from start to target. You can use Translate or Rigidbody, this is up to you.

Now the purpose is to seek for "heat", I would think this is mainly a way to make the difference between a character and the environment. In our case, we will consider that you have a list of potential target, if this is based on heat, then a fire will be on that list, which allows the player to lure the rocket for instance.

You could at a certain frequency, check for the closest item from the list, you could use a sorted list to spare the hassle of ordering. Then, you check if the distance between the rocket and the closest item is small enough to be considered. This range is up to you. If within range, then you change the target for that new target and translate your rocket towards that new target.

At first it will not look good because your rocket will suddenly change direction so you can work it out with some force principle to get the movement in a curve.

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 wijesijp · Feb 06, 2014 at 02:22 PM 1
Share

fafase thank you for your answer.

It seems I didn't explain what I wanted properly, sorry about that. The problem I am having is how to move the heat seeker rocket around the screen in a looping manner similar to $$anonymous$$ingdom Rush. I am trying to use a brazier curve equation to get similar effect but I couldn't get effect similar to $$anonymous$$indom Rush. Any idea how to do this?

avatar image fafase · Feb 06, 2014 at 04:06 PM 0
Share

Can you find a video where we can see the effect?

avatar image robertbu · Feb 06, 2014 at 04:51 PM 0
Share

@fafase - See this video at the 45 second mark.

avatar image wijesijp · Feb 06, 2014 at 05:29 PM 0
Share

yes that looks great. Here another clip I found. Around 49 he uses similar attack. The attack I have seen looks similar but loops around the screen 3,4 times before going for the target.

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

18 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Making a bubble level (not a game but work tool) 1 Answer

Rocket-styled angular drag 0 Answers

Enemy Approaching player and then stopping in front?? 1 Answer

How to properly make a rocket controller. 0 Answers


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