Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by fahadsharif · Aug 09, 2016 at 02:33 PM · missile

When target Dodge the missile then missile should complete the circle and then follow again.

Hello Everyone iam new in this field and i am trying to make Missiles type game available on Play Store. My Question is when target dorch the missile then it should complete a circle and then follow the target. And in my code it is simply following the target Here is my code. Thanks void FixedUpdate () {

     relativePos = target.position - transform.position;
     relativePos.z = 0;
     
     
     Rigidbody rb = GetComponent<Rigidbody> ();

     
     float angle = Mathf.Atan2(relativePos.y, relativePos.x) * Mathf.Rad2Deg;
     Quaternion    q= Quaternion.AngleAxis( angle, Vector3.forward);
     transform.rotation = Quaternion.Lerp(transform.rotation, q, Time.deltaTime *speed);
     
     
     
     rb.interpolation = RigidbodyInterpolation.Interpolate;
     
     Vector3 thrust = (relativePos).normalized * acceleration * Time.deltaTime;
     rb.velocity = rb.velocity * friction + thrust;

     Quaternion temp3=transform.rotation;
     temp3.x=0;
     temp3.y=0;
     //temp3.z = 0;
     transform.rotation=temp3;
 
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 fahadsharif · Aug 10, 2016 at 11:38 AM 0
Share

Sorry posted that in answers

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mrpmorris · Aug 09, 2016 at 03:09 PM

 var targetRotation = Quaternion.LookRotation(targetObj.transform.position - transform.position);
 transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);

From the first answer here

Note that "speed" is the turning speed of your missile, not its current velocity

Comment
Add comment · Show 9 · 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 fahadsharif · Aug 10, 2016 at 08:06 AM 0
Share

Thanks @mrpmorris. But i have done this before the thing i want is that when target dodge the missile it should move in the direction it is facing and then rotate towards target.

avatar image mrpmorris fahadsharif · Aug 10, 2016 at 08:11 AM 0
Share

If your missile is moving forwards with each FixedUpdate then it will

avatar image fahadsharif mrpmorris · Aug 10, 2016 at 08:38 AM 0
Share

@mrpmorris it is following the target like in above code at line 15 and it is in FfixedUpdate. but it does not work.

Show more comments
avatar image mrpmorris · Aug 11, 2016 at 10:18 AM 0
Share

Your link: https://youtu.be/6Yj9cfQl6sQ

Ah I see now. It is working perfectly but you want to limit the turn angle of the missile? You just have to lower the value of the speed variable (let's call it turnSpeed from now on), have you tried that?

avatar image fahadsharif mrpmorris · Aug 12, 2016 at 06:46 AM 0
Share

Thanks $$anonymous$$r. @mrpmorris but it does not work that much.

avatar image mrpmorris fahadsharif · Aug 12, 2016 at 06:57 AM 0
Share

What difference do you see by altering that "turningSpeed" attribute, and what do you want it to do differently?

Show more comments
Show more comments
avatar image
0

Answer by fahadsharif · Aug 10, 2016 at 11:37 AM

@mrpmorris here is the video missile is just following the target and when target dodge it it does not complete circle and then follow the target. Can't upload video here. Here is the link of video. Thanks for help. https://www.facebook.com/100009945845644/videos/319811238360402/

Comment
Add comment · Show 9 · 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 mrpmorris · Aug 10, 2016 at 12:12 PM 0
Share

It says the video is not available

avatar image fahadsharif mrpmorris · Aug 11, 2016 at 06:40 AM 0
Share

Sorry to disturb you $$anonymous$$r. @mrpmorris can you set my movement of missile in above code. Thanks

avatar image mrpmorris fahadsharif · Aug 11, 2016 at 07:06 AM 0
Share

Post a working link to a video clip of what is currently happening.

Show more comments
avatar image fahadsharif · Aug 11, 2016 at 11:19 AM 0
Share

@mrpmorris i posted the link here. Thanks

avatar image mrpmorris fahadsharif · Aug 11, 2016 at 01:02 PM 0
Share

The site wouldn't let me reply to that comment, so I added a new comment beneath my answer. Look for that, it's about the turn-angle of the missile.

avatar image fahadsharif mrpmorris · Aug 12, 2016 at 09:50 AM 0
Share

@mrpmorris yes it is working nice but it changes the shape of missile like backslash().Thanks

Show more comments
Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Missile Won't Attach as a Child of an Airplane. Why? 1 Answer

Trying to get missile to home in on player position instead of one fixed position 0 Answers

How can I achieve a homing missile to hover over or near player? 0 Answers

need script for launching missile 0 Answers

[Unity, beginner. Help me.]Fire five parabolic lines in the desired random direction. 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