Hello guys im currently needing help on Drag and Shoot Every time i go to drag it works but releasing it doesnt do anything but when i do it goes up a wall then its stuck there plz help heres my script hope you can help
public class BallControl : MonoBehaviour
{
private const float V = 1f;
public float power = 2f;
public float maxDrag = 5f;
public Rigidbody2D rb;
public LineRenderer lr;
Vector3 dragStartPos;
Touch touch;
private Vector3 dragReleasePos;
private void Update()
{
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
DragStart();
}
if (touch.phase == TouchPhase.Moved)
{
Dragging();
}
if (touch.phase == TouchPhase.Ended)
{
DragRelease();
}
}
void DragStart()
{
dragStartPos = Camera.main.ScreenToWorldPoint(touch.position);
dragStartPos.z = 0f;
lr.positionCount = 2;
lr.SetPosition(0, dragStartPos);
lr.SetPosition(1, dragStartPos);
}
void Dragging()
{
Vector3 draggingPos = Camera.main.ScreenToWorldPoint(touch.position);
draggingPos.z = 0f;
lr.positionCount = 2;
lr.SetPosition(1, draggingPos);
}
void DragRelease()
{
lr.positionCount = 0;
Vector3 dragReleasepPos = Camera.main.ScreenToWorldPoint(touch.position);
dragReleasePos.z = 0f;
Vector3 force = NewMethod();
Vector3 clampedForce = Vector3.ClampMagnitude(force, maxDrag) * power;
rb.AddForce(clampedForce, ForceMode2D.Impulse);
}
private Vector3 NewMethod()
{
return dragStartPos - dragReleasePos;
}
}