Jump to content

Coming up with coordinates for newly spawned group/unit


609_Relentov

Recommended Posts

I have a question about coming up with coordinates within DCS. I'm trying to understand how to come up with coordinates for a newly spawned group/unit relatively close to a group/unit I'm controlling. Secondly, given the heading of my unit, I'd like to also assign a second waypoint for the spawned group/unit that is heading in the same direction as my unit.

 

So, for example, lets say my location and heading is:

 

x: -7562.647060363

z: 294083.01907702 (what's the unit of measure for the x,z (y) coordinates?)

heading: 2.0943951023932 (what heading in degrees is this anyway? :) )

 

Now I want to spawn a group/unit going in the same direction but approximately 50 feet/~15 meters away, heading in the same direction, with a second waypoint approximately 5000 feet/~1500 meters away.

 

I've been playing with witchcraft (great tool [FSF]Ian - thanks!), so I'm able to spawn a group/unit via Lua dynamically but figuring out the coordinates relative to a "baseline" unit (e.g. a unit I control) has me stumped so far.

 

Thanks!

Link to comment
Share on other sites

x/y/z coordinates are in metres. Or meters, if you prefer. If I recall correctly, x is north/south (positive -> north) and z is east/west (positive -> east). y is altitude (positive -> higher). However there are some functions that take 2D coordinates, in which case x is north/south and y is east/west instead of being "up".

 

The heading is in radians. You can use math.deg(radians) in lua to convert from radians to degrees, and math.rad(degrees) for the other way.

 

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(math.deg(2.0943951))
119.99999986288
>

To offset units you use standard geometry, multiplying the distance you want to offset in each direction by the cosine or sine of the angle. Lua's math functions use radians.

 

function translate(position, heading, distance)
 local hdgrad = math.rad(heading) -- assumes heading is in degrees
 local vec = {
     x = distance * math.cos(hdgrad),
     z = distance * math.sin(hdgrad),
   }
 return { x = position.x + vec.x , z = position.z + vec.z , y = position.y }
end

You might want to experiment with this a bit to verify it's translating in the correction direction. e.g. translating {x=10,z=10} 10 metres at heading 0 or 360 results in {x=20,z=10} which is correct if x -> north.

Link to comment
Share on other sites

I'm having difficulty figuring out the current heading of a group/unit. I've looked through all of the Unit methods, but nothing seems to supply the heading. When creating an object you need to supply the ["heading"] property, so it seems you should be able to retrieve it...

 

Unit.getPoint() returns a vec3 table of the x,y,z (long/alt/latt) coordinates. Unit.getPosition() is similar (although I'm not sure what the "p" Vec3 is), but otherwise I don't see any methods that would return more about the unit's location/heading.

 

I tried searching but after perusing a few dozen results, I figured I'd try asking :).

 

Thanks!

Link to comment
Share on other sites

OK, thanks to Speed/Grimes' MIST I was able to figure it out in looking at mist.getAttitude()... I tested this in witchcraft and the heading value result matched what the unit heading was showing in F2 view:

 

heading_in_degrees = math.deg(math.atan2(unit_object:getPosition().x.z, unit_object:getPosition().x.x)+2*math.pi)

 

 

On to the next challenge! :)


Edited by 609_Relentov
Link to comment
Share on other sites

I'm having difficulty figuring out the current heading of a group/unit. I've looked through all of the Unit methods, but nothing seems to supply the heading. When creating an object you need to supply the ["heading"] property, so it seems you should be able to retrieve it...

 

Unit.getPoint() returns a vec3 table of the x,y,z (long/alt/latt) coordinates. Unit.getPosition() is similar (although I'm not sure what the "p" Vec3 is), but otherwise I don't see any methods that would return more about the unit's location/heading.

 

getPosition returns 3 entries making up the unit vector and p representing the vec3 point the object is located at.

 

getPoint returns only position

getPosition returns position and orientation

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...