how to rotate bullet towards enemydirection?
i've problem to rotate bullet towards in enemydirection in unity 2D.is there another way to do this instead of lookrotation?(i think this works only in unity 3D , because for rotating in unity2d we just change the z axis but when i debug Quaternion.lookrotation(dir) i've found the x, y, and w also had values so in vector.slerp the current rotation will changing smoothly to that!) here is my code
void Update() { if (targetposition != null) { var dir = (targetposition.position - transform.position); Quaternion _rotation = Quaternion.LookRotation(dir , Vector3.forward); Quaternion _current = transform.localRotation; transform.rotation = Quaternion.Slerp(_current, _rotation, Time.deltaTime );
// transform.position = Vector3.SmoothDamp(transform.position, targetposition.position, ref vel, 0.2f);
}
}
this code is for bullet instances and in enemyshoot i 've just instantiating bullets and pass the targetposition!
Your answer
Follow this Question
Related Questions
Delayed LookAt, but only on one axis 1 Answer
Quaternion.Slerp not working 1 Answer
How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer
Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers
Problem with Quaternion and Euler Angles 0 Answers