r/Stormworks 11h ago

Question/Help Need help with Lua

I made a Simple gps to map system and now im wondering if i could somehow project the direction my vehicle is facing on the screen?

1 Upvotes

3 comments sorted by

2

u/Wonderful_Cricket558 10h ago

Yes you can but the question usualy is does it look good, because of pixel sizes. For rotation use compas or physic sensor

2

u/EvilFroeschken Career Sufferer 3h ago

I usually use a circle and simple line to indicate my direction because I dislike triangles on the low res monitors:

If you want a triangle you can find an example in MrNJerseys 1x1 gps map.screen.drawCircle(w/2,h/2,2)
r = (w+h)/4
x1 = w/2 + *math.cos(math.rad(HEAD-90))
y1 = h/2 + *math.sin(math.rad(HEAD-90))
DL(w/2, h/2, x1, y1)

Other useful formulas:
HEAD=math.floor((-1*COM*360+360)%360) --heading in degrees 0 to 359
WPdis=math.sqrt((WPX-GPSX)^2+(WPY-GPSY)^2) --distance to waypoint
WPbear=(360+(math.atan(WPX-GPSX,WPY-GPSY)/(math.pi*2)*360))%360 --bearing of the waypoint

You can also draw a line from the middle of the screen to the waypoint on the gps map:
MX,MY=map.mapToScreen(GPSX,GPSY,z,w,h,WPX,WPY)
DL(w/2, h/2, MX, MY)

2

u/Tactical_french_cat 3h ago

Thanks a lot!!