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?

63563-vector.png

Thank you in advance.

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;

//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.positionnormVectorExtenDis;

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

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;