Spotlight Direction
I am trying to set the direction of a spotlight created from script. I have a normal which represent the direction but spotlights do not take normals as direction. How can I convert normals to degrees to then use Quaternion.Euleur(Vector3 v)
Better yet, can I directly convert the normals to represent the direction of the spotlight?
Answer by IgorAherne · Mar 13, 2017 at 01:42 AM
spotlight is just a light
light is just a component, much like any of your monobehaviors
components sit on gameObjects
gameObjects have Transform, accessible as this.transform
You can convert any vector for example new Vector3(0, 0, 1)
which in this case is a forward vector, by using Quaternion.LookRotation(myForwardsVector, myUpDirection)
which returns quaternion
you can already assign quaternion to transform.rotation
, but if you want degrees you can always get them like: myQuaternion.eulerAngles;
but wouldn't transform.LookRotation()
be easier for you?
Answer by treehuggernicky · Mar 16, 2017 at 07:30 AM
I took your advice and I am using this:
lightGameObject.transform.localRotation = Quaternion.LookRotation(normal,lightGameObject.transform.up);
Is there any case when this will fail? Cannot comment due to lack of permissions.
yes, if you need to keep light parallel to the ground. But in that case, just modify 1st argument, to have its y-component as zero (and don't forget to normalize the resulting vector)
Your answer
Follow this Question
Related Questions
GameObject Smooth Movement 0 Answers
iron sight using inverse kinematic 0 Answers
Acceleration and accelerometer calibration 0 Answers
Space Shooter Tutorial tilting extra 0 Answers