Why does this vector multiplication change its direction?

Hi, I’m using Unity 4 and spawning an object in the same position every second. Each time an object is spawned, a vector is drawn from the object to moveTowardsPos (the position of my player-character). I use the code in the Start() method to mark where I want my vector to be drawn to and the code in the Update() method to draw two vectors.

	void Start () {
	
		player = GameObject.FindObjectOfType<Player>();
	
		moveTowardsPos = player.transform.position;
		
		Vector2 direction = player.transform.position - transform.position;
		float angle = Mathf.Atan2(direction.y,direction.x) * Mathf.Rad2Deg + 270;
		Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
		transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 100.00f * Time.deltaTime);
	}
void Update () {
	
		Debug.Log (moveTowardsPos);
		
		Debug.DrawLine(this.gameObject.transform.position, moveTowardsPos, Color.green);
		Debug.DrawLine(this.gameObject.transform.position, moveTowardsPos * 2.0f, Color.red);

	}

I’m drawing a green vector that starts at my object and ends at moveTowardsPos (the position of my player-character). I want the red vector to be in the same direction as the green vector, but just twice as long.

However, this is what happens when I play the game: https://i.imgur.com/z8S7IgN.png

The red vector is longer than the green, but they are not in the same direction. A vector multiplied by 2 should just be a vector twice as long in the same direction, no?

Is there something I don’t understand about how vectors work in Unity? How can I have the red vector be in the same direction but just be twice as long?

Thanks in advance :slight_smile:

Hi, to draw a line you must enter the start and the end of the line NOT the direction. So it will not duplicate the direction but the end point vector. To solve this, simply subtract the transform.position like this:

Debug.DrawLine(this.gameObject.transform.position, moveTowardsPos, Color.green);
Debug.DrawLine(this.gameObject.transform.position, moveTowardsPos * 2.0f - transform.position, Color.red);