Difference between revisions of "DCS func getPosition"

From DCS World Wiki - Hoggitworld.com
(Adding information on orientation vector + example.)
 
Line 13: Line 13:
 
|par4=
 
|par4=
  
|desc= Returns a Position3 table of the objects current position and orientation in 3D space. X, Y, Z values are unit vectors defining the objects orientation. Coordinates are dependent on the position of the maps origin. In the case of the Caucuses theater, the origin is located in the Crimean region of the map.  
+
|desc= Returns a Position3 table of the objects current position and orientation in 3D space.
 +
 
 +
 
 +
X, Y, Z values are unit vectors, starting from the object's center, defining the object's orientation:
 +
* X points forward, extending 'out the front'
 +
* Y points upwards, extending 'out the top'
 +
* Z points to the right.
 +
 
 +
 
 +
Coordinates are dependent on the position of the maps origin. In the case of the Caucuses theater, the origin is located in the Crimean region of the map.  
  
 
Function also works with [[DCS_Class_Unit|Unit]], [[DCS_Class_Weapon|Weapon]], [[DCS_Class_Static_Object|Static Object]], [[DCS_Class_Scenery_Object|Scenery Object]], [[DCS_Class_Airbase|Airbase]]
 
Function also works with [[DCS_Class_Unit|Unit]], [[DCS_Class_Weapon|Weapon]], [[DCS_Class_Static_Object|Static Object]], [[DCS_Class_Scenery_Object|Scenery Object]], [[DCS_Class_Airbase|Airbase]]
Line 20: Line 29:
  
 
|rtnExample= Position 3 is a table consisting of the point and orientation tables.  
 
|rtnExample= Position 3 is a table consisting of the point and orientation tables.  
  Position3 = {   p = Vec3,
+
  Position3 = {
                x = Vec3,
+
  p = Vec3, -- Object world position, same as getPoint().
                y = Vec3,
+
  x = Vec3, -- forward vector
                z = Vec3 }
+
  y = Vec3, -- up vector
 +
  z = Vec3 -- right vector
 +
}
  
 
|reqType1= Class
 
|reqType1= Class
Line 46: Line 57:
 
     local Heading = math.atan2(unitpos.x.z, unitpos.x.x)
 
     local Heading = math.atan2(unitpos.x.z, unitpos.x.x)
 
     local Pitch = math.asin(unitpos.x.y)
 
     local Pitch = math.asin(unitpos.x.y)
 +
 +
Spawn a crate 10 meters in front of the unit.
 +
 
 +
    local unit = Unit.getByName('Alice')
 +
    local unitpos = unit:getPosition()
 +
   
 +
    local tenMetersInFront = {
 +
        x = unitpos.p.x + 10 * unitpos.x.x,
 +
        y = unitpos.p.y + 10 * unitpos.x.y,
 +
        z = unitpos.p.z + 10 * unitpos.x.z
 +
    }
 +
    coalition.addStaticObject(unit:getCoalition(), {
 +
        name = "Alice's cargo",
 +
        type = "uh1h_cargo",
 +
        x = tenMetersInFront.x,
 +
        y = tenMetersInFront.z -- y/z switcheroo converting from Vec3 to Vec2
 +
    })
  
 
|notes=  
 
|notes=  

Latest revision as of 13:16, 22 July 2024

Scripting Root

Envrioment: Mission Scripting
Function: getPosition Added with: 1.2.0
Member Of: Object, Spot
Syntax: Position3 Object.getPosition(Class Self )
Description: Returns a Position3 table of the objects current position and orientation in 3D space.


X, Y, Z values are unit vectors, starting from the object's center, defining the object's orientation:

  • X points forward, extending 'out the front'
  • Y points upwards, extending 'out the top'
  • Z points to the right.


Coordinates are dependent on the position of the maps origin. In the case of the Caucuses theater, the origin is located in the Crimean region of the map.

Function also works with Unit, Weapon, Static Object, Scenery Object, Airbase


Return Value: Position3
Return Example: Position 3 is a table consisting of the point and orientation tables.
Position3 = {
  p = Vec3, -- Object world position, same as getPoint().
  x = Vec3, -- forward vector
  y = Vec3, -- up vector
  z = Vec3 -- right vector
}
Examples: Assigns a value for the heading and pitch of the unit.
   local unit = Unit.getByName('Bob')
   local unitpos = unit:getPosition()
   local Heading = math.atan2(unitpos.x.z, unitpos.x.x)
   local Pitch = math.asin(unitpos.x.y)

Spawn a crate 10 meters in front of the unit.

   local unit = Unit.getByName('Alice')
   local unitpos = unit:getPosition()
   
   local tenMetersInFront = {
       x = unitpos.p.x + 10 * unitpos.x.x,
       y = unitpos.p.y + 10 * unitpos.x.y,
       z = unitpos.p.z + 10 * unitpos.x.z
   }
   coalition.addStaticObject(unit:getCoalition(), {
       name = "Alice's cargo",
       type = "uh1h_cargo",
       x = tenMetersInFront.x,
       y = tenMetersInFront.z -- y/z switcheroo converting from Vec3 to Vec2
   })
Related Functions: Object Functions: isExist, destroy, getCategory, getTypeName, getDesc, hasAttribute, getName, getPoint, getPosition, getVelocity, inAir
Notes: