Comments and answers for "Get the position behind an object (locally) ?"
http://answers.unity.com/questions/722047/get-the-position-behind-an-object-locally-.html
The latest comments and answers for the question "Get the position behind an object (locally) ?"Comment by Derptastic on Derptastic's answer
http://answers.unity.com/comments/1331641/view.html
$$anonymous$$ight I ask what would be the same solution in 2D space of your second piece of code (x units of distance behind given object)? Relative to the targeting object's position (the 'behind' should change, depending on the position of the **targeting** object, regardless of where the *target* is facing).Mon, 27 Mar 2017 10:05:56 GMTDerptasticComment by Nick4
http://answers.unity.com/comments/722053/view.html
Please be more specific. Is your game 2D or 3D? top-down or third person?Thu, 05 Jun 2014 17:49:25 GMTNick4Answer by rutter
http://answers.unity.com/answers/722051/view.html
Every GameObject has a [Transform component](http://docs.unity3d.com/ScriptReference/Transform.html), which can give you its local right, up, and forward vectors. In particular, multiplying [local forward](http://docs.unity3d.com/ScriptReference/Transform-forward.html) by `-1` will give you a "backwards" direction.
The following would give you a point one unit behind your target:
function GetBehindPosition(target : Transform) {
return target.position - target.forward;
}
Because the forward/right/up vectors are normalized (have a length equal to one), you can multiply them by any number `X` to get a point `X` units in that direction:
function GetBehindPosition(target : Transform, distanceBehind : float) {
return target.position - (target.forward * distanceBehind);
}
You can even mix and match your offsets:
function GetBehindPosition(target : Transform, distanceBehind : float, distanceAbove : float) {
return target.position - (target.forward * distanceBehind) + (target.up * distanceAbove);
}Thu, 05 Jun 2014 17:48:05 GMTrutter