I am making a 2D bow and arrow game, and I want there to be a predictive aiming line as you pull the bow back. The problem is, in my current script, it seems to only update every time I go to shoot, rather than updating as you pull the bow back. For clarity, it updates the direction, but not the increased force as you pull the bow back further.
I have put this for loop at the top of Update()
:
for(int i = 0; i < Points.Length; i++){
Points[i].transform.position = PointPosition(i * time);
}
That calls this method:
Vector2 PointPosition(float t){
force = new Vector2(Mathf.Clamp((startPoint.x - endPoint.x) / damp, powerMin, powerMax), Mathf.Clamp((startPoint.y - endPoint.y) / damp, powerMin, powerMax));
Vector2 currentPointPos = (Vector2)transform.position + ((-direction.normalized * (force*mult) * t) + 0.5f * Physics2D.gravity * (t*t));
return currentPointPos;
}
The predicted path is also wrong, but that is a problem for future me. For now, I'm just trying to figure out how I can get the predicted force of this line to update every second. The obvious solutions like setting force
at the top of Update()
didn't seem to work, and I don't know if I'm missing a Unity thing or if I've just been staring at my code for too long and can't see the obvious fix.