void Update()
{
//if (Input.GetMouseButtonDown(0))
{
reach();
}
}
void reach()
{
// find screen pos of tongue
Vector2 tongue_pos = Camera.main.WorldToViewportPoint(transform.position);
// find screen pos of mouse
Vector2 mouse_pos = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition);
// calculate angle between points
float angle = Mathf.Atan2(tongue_pos.y - mouse_pos.y, tongue_pos.x - mouse_pos.x) * Mathf.Rad2Deg;
// calculate the distance between the points
float distance = Vector2.Distance(tongue_pos, mouse_pos);
// rotate tongue to face mouse
transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
// stretch tongue out to cursor
transform.localScale = new Vector3(distance*10, transform.localScale.y, transform
}
I’m trying to stretch this object on it’s localscale.x out to the position of the cursor. I thought setting the localScale.x to the distance between the object’s pivot and the position of the mouse cursor would do it, but that didn’t seem to work. Multiplying that distance by 10 seems to work when the object is scaling vertically but not horizontally. I can’t work out what the problem is. Any advice?