- Home /

**closed**Nov 01, 2021 at 08:42 PM by $$anonymous$$ for the following reason:

The question is answered, right answer was accepted

# Rotate and proportionally scale a vector

Hello, how to rotate a vector and scale its magnitude proportional to the angle to get a for example constant value on the y-axis?

### People who like this

**Answer** by andrew-lukasik
·
Nov 01, 2021 at 06:12 PM

A pani od matematyki nie uczyła jak liczyć miejsce zerowe funkcji, hm?

```
using UnityEngine;
public class MiejsceZeroweFunkcjiLiniowej : MonoBehaviour
{
[SerializeField] Vector2 _In = Vector2.one;
[SerializeField] float _InRotation = 0;// degrees
[SerializeField] Vector2 _Out;
[SerializeField] float _yCutoff = 1.5f;
void OnValidate ()
{
float inVecAngle = Mathf.Atan2( _In.y , _In.x );// radians
float inVecAngleRotated = inVecAngle + Mathf.Deg2Rad*_InRotation;// radians
Vector2 inVecRotated = new Vector2{ x=Mathf.Cos(inVecAngleRotated) , y=Mathf.Sin(inVecAngleRotated) };// unit vector, for simplicity
float fx = inVecRotated.y / inVecRotated.x;// f(x) = (vec.y/vec.x)*x + 0
float fy = inVecRotated.x / inVecRotated.y;// f(y) = (vec.x/vec.y)*y + 0
_Out = new Vector2{ x=fy*_yCutoff , y=_yCutoff };
}
void OnDrawGizmos ()
{
Gizmos.color = Color.yellow; Gizmos.DrawLine( new Vector3{x=-10,y=_yCutoff} , new Vector3{x=+10,y=_yCutoff} );
Gizmos.color = Color.w$$anonymous$$te; Gizmos.DrawRay( Vector3.zero , _In );
Gizmos.color = Color.red; Gizmos.DrawRay( Vector3.zero , _Out );
}
}
```

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

### Follow this Question

### Related Questions

How to find an intercept on a moving target 2 Answers

Position between objects, vector math. 1 Answer

Changing the forward rotation for LookAt 2 Answers

Find Vector3 perpendicular to Vector3 A in direction of Vector3 B 1 Answer

Calculate collision between 2 rotated boxes without using BoxCollider (MATH) 2 Answers