- Home /
Position on a Vector3 at specific distance
I have a grid in which individual cells are focused on to and the camera pans so that it's on a vector drawn from the grid's center and through the cell. I am trying to set the camera at a certain distance from the cell on the vector, but can't get the math right. Simply factoring the vector obviously gives varying distance, although it is on the vector. Adding to it gives errors or I'm not doing that right.
Vector3 diff = target.position - container.transform.position;
That'd be the vector between container and the currently focused grid cell. What do I have to do to diff to find the position on the vector on the other side of the cell at a distance, say, 4?
EDIT: (can't seem to remove the question on my own)
Five minutes after posting this I arrive to the conclusion, I think, on my own:
Vector3 camPos = cell.position + diff.normalized * 4;
Good work finding the answer. Put in in an actual answer and mark it answered; this doesn't need to be deleted. It may help someone.
Answer by Dralamir · May 10, 2012 at 02:57 PM
Here's the solution in C# (also edited in the first post):
Vector3 camPos = cell.position + diff.normalized * 4;
Or in JS:
var camPos:Vector3 = cell.position + diff.normalized * 4;
Your answer
![](https://koobas.hobune.stream/wayback/20220613071326im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
distance to variable object 1 Answer
Reposition to minimum distance from target 2 Answers
how do i fix my script in the content below? 0 Answers
Return to Start Position 1 Answer
Vector3.Project, how to? 2 Answers