GetDistance - ObjectReference

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

Member of: ObjectReference Script

Calculates the distance between this object and the passed in one.

Syntax[edit | edit source]

float Function GetDistance(ObjectReference akOther) native

Parameters[edit | edit source]

  • akOther: The object to find the distance to.

Return Value[edit | edit source]

The distance between this object and the other one. (Objects should be in the same interior, or same worldspace, otherwise this will be a very large number)

Examples[edit | edit source]

; Find out how far away the player is from the chest (assuming they are in the same interior or worldspace)
Debug.Trace("Player is " + Game.GetPlayer().GetDistance(Chest) + " units away from the chest")

Notes[edit | edit source]

  • If you are wanting to know when something is closer or farther then a specified distance from another one, you should instead use RegisterForDistanceLessThanEvent or RegisterForDistanceGreaterThanEvent instead of constantly checking the distance using this function manually which is less efficient.
  • Calling this function on an actor to check the distance of an objectreference will result in distance larger than expected. Where as calling said objectreference on an actor(even the same actor) will return a correct value. Source

See Also[edit | edit source]