- Home /
How to get point a set distance along a direction
Hi all, I have an angle. And I have a distance from an origin point.( in 3d but only on two axes - game will be top down) What I want is to find another point that is the distance in the direction of the angle. Im sure this is super easy but Im just not getting it right. I had been trying to work out the position values using Pythagoras' theorem but no joy.
ok since I have the distance(hypotenuse) and the angle, ive tried : adjacent = hypotenuse ($$anonymous$$athf.Cos(angle)); opposite = hypotenuse ($$anonymous$$athf.Sin(angle));
I then add the opposite value to the z component and adjacent value to the x component of the position vector of the object.
If you normalise a Vector you get the Unit Vector, which is a directional vector 1 unit in magnitude. You can multiply this by some magnitude to point further along that direction. The vector itself always points the same relative direction.
Can you do anything with this snippet of info?
It would help to edit your question to provide some context. There are a few ways to do this and I guess it depends on what exactly you are trying to do.
What Im trying to do is generate a regular polygon around a central point. The reg polygon shape is assembled using cubes.That part works just dandy. I can generate anything from a triangle to a 16 sided poly and beyond. But the point I start generating is user set. I want it to construct itself around the player position (with the player being central). So the distance Im talking about is the radius of the regular poly. I use this formula :
radius = (wallLength)/(2 * ($$anonymous$$athf.Sin(180/numWalls)))
To get the angle I use 360/numWalls So the point Im trying to find is (on a square for example) the top left corner.
Here is a webplayer of the tunnel that is generated https://t.co/kT7HwTZUDt
So the camera is central and facing down. so the y values in the positions are handled, its just x,z i need to get
Answer by MakakWasTaken · Mar 30, 2015 at 11:35 AM
You could try this:
float angle = 3.0f;
Quaternion Rot = Quaternion.AngleAxis(angle,Vector3.forward);
Vector3 Dir = Rot * Vector3.forward;
Vector3 WorldDir = transform.TransformDirection(Dir);
would that result in a specific point though? would I need to multiply WordDir by the distance(distance I want the point to be from the origin)
Yes, you should multiply it by the desired distance from the origin.
Hmmm not sure Im fully clear... So for example, the distance is 4 and the angle is 60degrees and the camera is at origin. What would the C# look like?
float angle = 60.0f;
Quaternion Rot = Quaternion.AngleAxis(angle,Vector3.forward);
Vector3 Dir = Rot * (Vector3.forward * 4);
Vector3 WorldDir = Camera.main.transform.TransformDirection(Dir);
This should do it.
thanks! ill give it a go later. I need to get my head around the 3d positioning stuff a bit.