Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Set forward vector of an object to be EXACTLY equal to another vector.

$
0
0
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: 1. The center of the cone passes through the RaycastHit.point Vector3 2. 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.

Viewing all articles
Browse latest Browse all 171066


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>