- Home /
Set forward vector of an object to be EXACTLY equal to another vector.
I have been racking my brain over this for a couple hours now but I can't figure this out.
I have a spotlight object. This spotlight has a special shader and texture on it to give it the spotlight cone effect. It's not an actual spotlight, it's just a cone mesh with a texture.
Every frame, a raycast is fired from the player's mouse position. The spotlight must rotate such that it satisfies the following conditions:
The center of the cone passes through the RaycastHit.point Vector3
The tip of the cone remains in its initial location (the lamp object which is emitting this "light")
I've got it working with arrow keys:
transform.RotateAround(rotateAround.position, Vector3.right, vertical);
transform.RotateAround(rotateAround.position, Vector3.up, horizontal);
I use a Transform called "rotateAround" which serves as the "anchor" point, so to speak, for the spotlight. It rotates around this point based on the vertical and horizontal input axes. It rotates around the right axis to move it up and down, and it rotates around the up axis to move it left and right.
But now I need to make this work with a point in space. I want to rotate the cone such that the line that passes through the tip and the center of the base also passes through the raycast hit point while also keeping the tip stationary.
"the line that passes through the tip and the center of the base also passes through the raycast hit point while also keeping the tip stationary"
HUH ??
You'd have to add a diagram champ. That's the most confusing thing I've ever heard and I used to read books on topology. Plus it's totally different from the title.
it's very likely you just add a wrapper object with the center at "some point" and then move the wrapper object to, uh, the other point
Use shenanigans to make your pivot point an object. Either create a new object and child the cone to it, or fix the cone's mesh so its pivot is at its tip. Save yourself eight million headaches, trust me.
Answer by whydoidoit · Apr 07, 2013 at 04:42 PM
You can set the forward vector using
transform.forward = theVectorYouWant;
Or by using:
transform.rotation = Quaternion.LookRotation(theVectorYouWant);
This doesn't solve the problem of keeping the tip of the cone stationary.
Why are you moving it then? I must have missed something.
Answer by MikeNewall · Apr 07, 2013 at 03:49 PM
I think if you had a parent gameobject which shares the same position as the point of your cone it should work. You can use the parent gameobjects transform in place of "rotateAround". It's just a case of having the pivot point in the place you want to rotate around.
Your answer
Follow this Question
Related Questions
Raycast Rotate Help 1 Answer
transform.Rotate(Vector3.up ... not working 0 Answers
Plane Control Script rotating unexpectedly 1 Answer
Rotate Around Object 2 Answers