I’m trying to set a Vector3 rotation value based on camera orientation. I found 2 snippets of script that I think can help, but I’m not sure how to make them work in context. The first snippet sets the rotation directly based on the camera transform:

```
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
targetDirection = Camera.main.transform.TransformDirection(targetDirection);
targetDirection.y = 0.0f;
```

The other rotates a game object to the nearest 90 degree axis:

```
Vector3 vec = transform.eulerAngles;
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
transform.eulerAngles = vec;
```

What I want is to get a Vector3 rotation value based on the 90 degree axis that the camera transformation rounds to. Any advice on this?

My first instinct was to do something like the following (using an empty placeholder game object as “coordSys”)

```
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
Vector3 vec = Camera.main.transform.eulerAngles;
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
coordSys.eulerAngles = new Vector3(x, y, z);
targetDirection = coordSys.transform.TransformDirection(targetDirection);
targetDirection.y = 0.0f;
```

This works for some camera angles, but other times it does not