- Home /
Question by
Andrew_Best · Dec 02, 2014 at 04:13 AM ·
lightmousefollow
Eye Follow Mechanics on Light
I'm currently trying to get similar mechanics to an eye following the mouse, but the only moving part is a light (there is no eyeball)
I'm having two issues, and they are:
The light moves from it's position to the centre of the screen
The light moves away from the mouse as opposed to towards
Here is my code
public float m_EyeRadius = 100.0f;
private Vector3 distanceToTarget_;
private Vector3 finalPos_;
void Update ()
{
distanceToTarget_ = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z)) - transform.position;
distanceToTarget_ = Vector3.ClampMagnitude(distanceToTarget_, m_EyeRadius);
finalPos_ = transform.position + distanceToTarget_;
transform.position = new Vector3(finalPos_.x, finalPos_.y, transform.position.z);
}
Perhaps someone else can see where I'm going wrong in this, but I'm drawing a blank at the moment. This script (and this is the entire thing) is attached to the light.
Comment
Your answer
Follow this Question
Related Questions
Using shadows as Triggers? 1 Answer
Can't get dynamic shadows working 1 Answer
Flashlight origin effect 2 Answers
Light Mapping Question - Individual objects/prefabs 0 Answers