Sameer Hussain
Sameer Hussain

Reputation: 2551

Find vector3 in a direction but with a given magnitude

I get the direction by subtraction of two vector3. In this case my gameObject and my mouse position.

Vector3 dir = gameObject.transform.position -
orthoCamera.ScreenToWorldPoint(Input.mousePosition)

I now want to place an object in the same direction but at a limited distance from my original gameobject. That is I need a vector in the same direction but with a magnitude of 0.5. How do I do that ?

Upvotes: 0

Views: 1484

Answers (1)

Immersive
Immersive

Reputation: 1704

var posn = gameObject.transform.position - (dir.normalized * desiredDistance);

Hopefully this doesn't sound too condescending, but you change a vector's magnitude by multiplying it with a scalar.

Upvotes: 1

Related Questions