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;
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
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.
If your missile is moving forwards with each FixedUpdate then it will
@mrpmorris it is following the target like in above code at line 15 and it is in FfixedUpdate. but it does not work.
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?
Thanks $$anonymous$$r. @mrpmorris but it does not work that much.
What difference do you see by altering that "turningSpeed" attribute, and what do you want it to do differently?
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/
Sorry to disturb you $$anonymous$$r. @mrpmorris can you set my movement of missile in above code. Thanks
Post a working link to a video clip of what is currently happening.
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.
@mrpmorris yes it is working nice but it changes the shape of missile like backslash().Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612090442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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