- Home /
Question by
GameDevH2O · Apr 23, 2021 at 03:10 AM ·
c#2dscalingrotatearound
How to orbit/rotate around a gameobject while re-scaling its Y axis. (2D)
Hello, I have a script that re-scales the gameobject Y axis based off drag.
public float sizingFactor = 0.02f;
public float min, max;
private float startY;
private Vector3 zAxis = new Vector3(0, 0, 1);
Vector3 pos;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
startY = position.y;
position = Camera.main.ScreenToWorldPoint(position);
transform.localScale = new Vector3(transform.localScale.x, 0, transform.localScale.z);
}
if (Input.GetMouseButton(0))
{
Vector3 size = transform.localScale;
size.y = (Input.mousePosition.y - startY) * sizingFactor;
transform.localScale = -size;
pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
transform.localScale = new Vector3(Mathf.Clamp(transform.localScale.x, min, max), Mathf.Clamp(transform.localScale.y, min, max),Mathf.Clamp(transform.localScale.x, min, max));
}
}
Works great but I need help rotating the gameobect around another gameobject based off the drag, facing the opposite direction. Help Needed.
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
when changing size of gameobject bounds do not change 1 Answer
Complex object scaling 0 Answers
Distribute terrain in zones 3 Answers
Scaling related to damage 2 Answers