# How do I programmatically specify direction from a given vector?

I’m hoping this is incredibly easy, but I’ve been smashing my head against a wall over this without much luck- let’s say I have three variables:

``````Vector3 PlayerLocation; //Represents current player location
float spawnDirection; //Always clamped between 0-360
float spawnRange; //Represents desired distance from player at which objects should spawn
``````

What I’m trying to do is get a Vector3 representing a transform spawnRange distance from PlayerLocation in spawnDirection, where spawnDirection=0 corresponds to player.forward, 90 corresponds to player.right, and so forth. Is there an easy way to do this? I’m half-suspicious that the math is trivial, but I can’t quite suss out how to do it.

since the player has a transform you know its forward. You can then do
Vector3 spawnVector = player.transform.forward * Quaternion.Euler(0,spawnDirection,0);

This rotates the vector about the given degrees. Then adjust the magnitude:
spawnVector *= spawnRange;

And then get the final SpawnPosition:
Vector3 spawnPosition = player.transform.position + spawnVector;