Question by
jbaujb · Jan 10, 2020 at 11:35 AM ·
vector3rotatearoundpivot
Rotate a position vector relative to another position vector
I want to draw a circle around my object on a vertical plane which I am doing with the code below. However, I want the circle to rotate with the game object its attached to, so that it is align with the forward of the object.
var calcAngle = 360f;
var start = newPosition;
// Calculate Arc on Y-Z
while (calcAngle >= 0)
{
var nextRadian = calcAngle * Mathf.Deg2Rad;
var posY = Mathf.Cos(nextRadian) * targetMagnitude;
var posZ = Mathf.Sin(nextRadian) * targetMagnitude;
var end = newPosition;
end.y += posY;
end.z += posZ;
Debug.DrawLine(start, end, Color.yellow);
calcAngle -= 18f; // angle between each segment
start = end;
}
I have tried multiplying the vector by the rotation but that gives a weird result. How do I do this?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612221329im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cant Get a Bullet to Shoot (C#) 2 Answers
Split string into three pieces? 1 Answer
Vector3 not an identifier? 1 Answer
Need help with coordinate conversion. 1 Answer
Problem with Crouch Script - 3D C# 2 Answers