Answers for "unity making homing missile"


unity making homing missile

//using the cross-product is quite effective 
//Note: This is quite usefull for rigidbodys... 
//but you can also use that for transform with some code adjustments
Vector3 targetDir;
Vector3 currentDir = transform.forward; //whatever your currentDir is

//the cross product returns the axis you want to rotate around
Vector3 crossProduct = Vector3.cross(targetDir, currentDir);
float magnitude = crossProduct.magnitude;
rigidbody.angularVelocity = crossProduct.normalized * speed * magnitude;
Posted by: Guest on June-20-2020

C# Answers by Framework

Browse Popular Code Answers by Language