PositionRelativeXYZ

From the Oblivion ConstructionSet Wiki
Revision as of 09:06, 1 December 2009 by imported>QQuix (A user function to position an object relative to another object)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A User Function for use with Oblivion Script Extender

Syntax:

PositionRelative refAnchor DeltaX DeltaY DeltaZ DeltaAngZ

Positions an object relative to another object. E.g.: positioning a parrot at the a pirate's shouder .


Notes:

  • This function must be called on a reference (Ref.call <function>)


Example:

Positioning three objects lined up at eye level in front of the player:

if refObj1.getparentcell != player.getparentcell
    refObj1.moveto player  ; avoid using moveto every frame
    refObj2.moveto player
    refObj3.moveto player
endif

refObj1.call zPositionRelativeXYZ player (-20) 50 120 0
refObj2.call zPositionRelativeXYZ player 0 50 120 0
refObj3.call zPositionRelativeXYZ player 20 50 120 0


Code

 scn zPositionRelativeXYZ

float posX
float posY
float posZ
float angZ
float dposX
float dposY
float dposZ
float dangZ
float angZanchor 
ref refAnchor 
 
begin Function { refAnchor dposX dposY dposZ dangZ} 
   let angZanchor :=  refAnchor.getangle z
   let posX := refAnchor.getpos x + dposX * cos angZanchor + dposY * sin angZanchor 
   let posY := refAnchor.getpos y - dposX * sin angZanchor + dposY * cos angZanchor 
   let posZ := refAnchor.getpos z + dposZ
   let angZ := refAnchor.getangle z + dangZ

   setpos X posX
   setpos Y posY
   setpos Z posZ
   setangle Z angZ

end

See Also