Movement Relative to Another Object

Function to move an object reference to a position relative to another object reference.

FunctionEdit

Function MoveRefToPositionRelativeTo(ObjectReference akSubject, ObjectReference akTarget, Float OffsetDistance = 0.0, \
  Float OffsetAngle = 0.0, bool FaceTarget = False) Global
	float AngleZ = akTarget.GetAngleZ() + OffsetAngle
	float OffsetX = OffsetDistance * Math.Sin(AngleZ)
	float OffsetY = OffsetDistance * Math.Cos(AngleZ)
	akSubject.MoveTo(akTarget, OffsetX, OffsetY, 0.0)
	if (FaceTarget)
		akSubject.SetAngle(akSubject.GetAngleX(), akSubject.GetAngleY(), akSubject.GetAngleZ() + \
		  akSubject.GetHeadingAngle(akTarget))
	endif
EndFunction

ParametersEdit

  • akSubject: The object reference to be moved.
  • akTarget: The target reference to move to.
  • OffsetDistance: The distance the subject should be moved to relative to the target.
    • Default: 0.0
  • OffsetAngle: The angle the subject should be moved to relative to the target.
    • Default: 0.0
  • FaceTarget: Whether the subject should face the target or not.
    • Default: False

Return ValueEdit

None.

ExamplesEdit

; Move Bob 256 units to the right of Joe
MoveRefToPositionRelativeTo(Bob, Joe, 256.0, 90.0)


; Move Bob 128 units behind and to the left of Joe, and turn to face him
MoveRefToPositionRelativeTo(Bob, Joe, 128.0, -135.0, True)