rotate a vector unity code example
Example 1: unity 2d rotate towards direction
private void RotateGameObject(Vector3 target, float RotationSpeed, float offset)
{
Vector3 dir = target - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, angle + offset));
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, RotationSpeed * Time.deltaTime);
}
Example 2: unity rotate vector
Vector3 rotated = Quaternion.AngleAxis(-45, Vector3.up) * vector;
Example 3: unity rotate vector3
Quaternion rotation = Quaternion.Euler(x,y,z);
Vector3 myVector = Vector3.one;
Vector3 rotateVector = rotation * myVector;