- Home /
ray direction to quaternion
I have a gun that fires using raycasts. I am now trying to spawn a particle effect at the point where the ray hits something and rotate it to face back along the ray, but all I can find is the direction of the ray as a normalised Vector3. Does anybody know how to get from this to a quaternion that can be used for rotation?
-(normalised vector3) is going back along the path of your normalised vector3. Simply use it and some Vector3.Angle (or whatever) to calculate your rotation from the particle starting rotation or facing vector.
I fuzzy on what you are asking. If face means forward, then you can rotate your particle effect this way:
transform.rotation = Quaternion.LookRotation(-RayDirection);
@robertbu Face does not mean forward (From Google: Face, Verb. Be positioned with the face or front toward (someone or something): "he turned to face her".) Anyways, your suggestion of Quaternion.LookRotation was exactly what I needed, thankyou.
"If face means forward" is my shorthand for, "if the side you want facing the raycast is the local forward of the object." Lots of questions on UA about facing something. Using LookRotation() only works to make something face the correction direction if the face of the object is the side that is the forward. That is the side facing positive 'z' when the rotaiton is (0,0,0). Often in 2D, the face is the right or up of the object ins$$anonymous$$d of forward, and LookRotation() will not work without correction.
Then apologies for the misunderstanding, and a suggestion to say what you mean ins$$anonymous$$d of your personal shorthand, which doesn't necessarily carry the same meaning to other people as to you.
Your answer
Follow this Question
Related Questions
Changing position of a RayCast 1 Answer
Detect if raycast hit the specific object. 1 Answer
Physics.Raycast intermittently stops working 1 Answer
Raycast on touch 3 Answers
Problem with raycasting when checking neighbouring objects? 0 Answers