Get a Vector3 to always have a radius of 1 from 0, 0, 0

Basically say I have a Vector3. I want to make it so that if the origin is and always is 0, 0, 0, how I can get it so the Vector3 will always be a radius of 1 away from that point, but is still pointing in the same direction toward 0, 0, 0.

I’m pretty sure the way you would do this in a 2D plane is to draw a circle around 0, 0 and figure out the radius of that, then divide both the X and Y by that radius. I haven’t tested that but it sounds like that is the way to go. I don’t know how I would do that in a 3D plane though.

I’d imagine this is gonna be really complicated and the math this requires is gonna be crazy, but I’d imagine it’s also just a copy-and-paste situation. Don’t feel like you need to explain why it works if you don’t want to.

In case you’re wondering why I need this, I’m trying to create a mechanic that makes the Physics.gravity based on the player’s collision’s hit point and the transform of the player. The problem is despite my efforts the gravity keeps on getting set too strong, I just want to have this ran every few frames. If there’s a better way to do it than this, I’d prefer that solution instead if you’d be willing to tell me!

I’d really appreciate any help, thank you for reading!

Hello are you just trying to determinate a “gravity” direction?

You know there is the LookAt funciton and the Normalize function?


Hey, well in general tormentoarmagedoom is right.
There is the function Vector3.Normalize(YOURVECTORHERE); which will return the vector you feed in with a length of 1.
This is also nothing really “fancy or crazy math” as you described it. Well at least as long as you’ve heard of the theorem of Pythagoras that is. But nonetheless just use the function provided by unity.

in any case there is also the following possibility: Assume you have a Vector3 testVector
then you can always access the normalized version by testVector.normalized.

this basically gives you a given direction with a vector length of 1, so the given point is basically on a sphere with radius 1 around the origin. (even though this description of yours is a bit fancy :))