609_Relentov Posted July 12, 2016 Share Posted July 12, 2016 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 More sharing options...
nomdeplume Posted July 12, 2016 Share Posted July 12, 2016 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 } endYou 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 More sharing options...
609_Relentov Posted July 12, 2016 Author Share Posted July 12, 2016 Great, thanks nomdeplume! I figured I'd need to use some math - you've given me a great start so I'll do some more experimenting. Link to comment Share on other sites More sharing options...
609_Relentov Posted July 13, 2016 Author Share Posted July 13, 2016 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 More sharing options...
609_Relentov Posted July 13, 2016 Author Share Posted July 13, 2016 (edited) 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 July 13, 2016 by 609_Relentov Link to comment Share on other sites More sharing options...
Grimes Posted July 13, 2016 Share Posted July 13, 2016 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 Server, Scripting 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 More sharing options...
609_Relentov Posted July 13, 2016 Author Share Posted July 13, 2016 Thanks Grimes - I'm still trying to wrap my head around vec2, vec3, point, position, etc, ... I'm reading and re-reading part 1 of the Hoggit SSE site... It will eventually sink in! :) Link to comment Share on other sites More sharing options...
ESAc_matador Posted July 13, 2016 Share Posted July 13, 2016 One they there will be a clic, and you start doing great progress! Keep on going! Link to comment Share on other sites More sharing options...
Recommended Posts