- Home /
Question by
Houkouha · Sep 25, 2020 at 06:09 PM ·
cursorzoomscreentoworldpoint
Bring object on hover closer
I' trying to make a table where each objects is hoverable, when it is, the object comes closer to the camera a bit (zoom on it).
However, the objects with the below code seem to fly to center. The logic is to have an object in 12f distance from the camera -> if i hover over it, it should come closer to the camera by the zoom amount - while it's still under the cursor (it should come on the ray that goes from the cursor onto it).
private void OnMouseOver()
{
Vector3 mouse = Input.mousePosition;
//mouse = -mouse;
mouse = Camera.main.ScreenToWorldPoint(mouse);
mouse.z = -12f;
goal = (mouse - transform.position).normalized * zoom;
}
private void OnMouseExit()
{
goal = position;
}
private void Zoom()
{
transform.position += (goal - transform.localPosition) * speedFactor * Time.deltaTime;
}
Comment
Your answer

Follow this Question
Related Questions
Camera.main.ScreenToWorldPoint not working 0 Answers
Rotate sprite to face direction of movement 1 Answer
Issue with moving the custom cursor sprite 0 Answers
mouse Input Instantiate 0 Answers
Look at mouse problem 1 Answer