- Home /
Question by
Essexrookie · Jul 24, 2020 at 06:27 PM ·
2dscaledraglimit
Scale/Resize gameobject's y axis based off drag (help)
Hello, I have a triangle around a gameobject that is used to point to the direction to shoot. I have the triangle rotating nicely but im having trouble scaling its Y axis based off a touch position & drag. I wanted it to have like a max limit to the scale so Im using clamp magnitude & it is not coming out the way I expected not sure what to do.
Vector3 startpos, dragpos;
public float radius;
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
Vector3 mousePosition = Input.mousePosition;
startpos = Camera.main.ScreenToWorldPoint(mousePosition);
}
if ( touch.phase == TouchPhase.Moved)
{
Vector3 mousePosition = Input.mousePosition;
dragpos = Camera.main.ScreenToWorldPoint(mousePosition);
Vector2 offset = dragpos - startpos;
Vector2 scale = Vector2.ClampMagnitude(offset, 1f);
triangle.transform.localScale = new Vector2(0.85f, A.y * scale.y);
triangle.transform.position = transform.position + radius * (startpos - dragpos).normalized;
}
Comment