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
– FattieUse 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.
– Loius