- Home /
Extending a vector?
Hi,
My problem is more of a basic vector maths problem then a scripting problem.
I want to be able to make a vector longer. I have a vector from the origin of one circle to the point of origin on another circle and I want to be able to use this vector to find an Extended vector represented in green of a different magnitude.
Does anyone have any ideas of how to do this?
Thank you in advance.
Answer by mikelortega · Feb 10, 2016 at 11:24 AM
Multiply your vector by a scalar. Check this.
Vector3 extended_vector = your_vector * (float);
To extend it to a known magnitude, you can first normalize your original vector:
your_vector.Normalize();
Vector3 extended_vector = your_vector * the_magnitude_you_want;
Answer by Guhanesh · Feb 10, 2016 at 12:09 PM
//Let the bigger circle centre position be A and smaller circle position be B and Extended
// position be C
public float float ExtenDis=5;
Vector3 normVector = (A.position-B.position).normalized;
B.position=B.position*normVector*ExtenDis;
I guess you mean:
Vector3 normVector = (B.position-A.position).normalized;
C.position = A.position + normVector*ExtenDis;
Answer by 5c4r3cr0w · Mar 12, 2016 at 02:43 PM
Okay lets say bigger circle has c1 center and smaller circle has center c2. So the direction will be c2 - c1 . Now you need to normalize vector so the magnitude becomes 1 and then multiply it with any digit so it can be extended to your desired position.
Here is some code :
public Transform c1, c2, res;
public float unit;
Vector3 result;
void Start ()
{
result = c2.position - c1.position;
res.position = result.normalized;
}
void Update ()
{
result = res.position * unit;
Debug.DrawRay (c1.position, result);
}
Tweak the value of unit so you get desired results.
Hope this helps
Answer by toddisarockstar · Mar 12, 2016 at 05:10 PM
you can simply subtract two vector threes to get direction. then simply add it to go past your second point.
var heading:Vector3;
var howfarpas:float;
howfarpast=.5;
var yournewspot:Vector3;
heading = target.position - player.position;
heading=heading*howfarpast;
yournewspot = target.position+heading;
Your answer
Follow this Question
Related Questions
how i can write a text from another code ? 2 Answers
Staring a 2D game 2 Answers
Unable to fully rotate GameObject on tap 2 Answers
Incorrect usage of Vector3.Dot? 0 Answers
Given a vector, how do i generate a random perpendicular vector? 5 Answers