As you see, the line renderer behaves in a very strange way.
I want that the line renderer middle point be attached like to the mouse position.
I hope someone could show me the problem. Here is the code:
public class Bow : MonoBehaviour {
public GameObject line;
public float maxStretchDistance;
float currentStretchDistance;
Vector3 mousePosition;
Vector3 bowDirection;
Vector3 mousePositionInRelationToLineCenter;
void Update() {
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward * 10;
mousePositionInRelationToLineCenter = mousePosition - line.transform.position;
}
void OnMouseDrag()
{
bowDirection = -(mousePosition - this.transform.position);
bowDirection.Normalize();
transform.right = bowDirection;
line.GetComponent<LineRenderer>().SetPosition(1, mousePositionInRelationToLineCenter);
}
void OnMouseUp()
{
line.GetComponent<LineRenderer>().SetPosition(1, Vector3.zero);
}
}
Thank you in advance