Rotation code in Martian Control

Hey gang!

I’m trying to adapt Jon’s code from Martian Control, using the Rotation Code he’s added but it does weird things.

Has anyone successfully used this code?

My object, while following a drawn line, will wildly spin from left to right and top to bottom at random intervals.
Outputting the angle to the console confirms it and I don’t know how to stop it.

Here is a sample of the output:

Angle = -44
Angle = -79
Angle = -85
Angle = 266
Angle = 265
Angle = 263
Angle = 261
Angle = 256
Angle = 244
Angle = 180
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 18
Angle = 14
Angle = 8
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 25
Angle = 20
Angle = 13
Angle = 0
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 16
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 24
Angle = 16
Angle = 0
Angle = 0
Angle = 0
Angle = 180
Angle = 22
Angle = 0
Angle = 0
Angle = 180
Angle = 30
Angle = 22
Angle = 0
Angle = 0
Angle = 180
Angle = 43
Angle = 42
Angle = 41
Angle = 39
Angle = 34
Angle = 0
Angle = 180
Angle = 43
Angle = 43
Angle = 42

I’ve tried hacking in ways around it, but it makes no sense to me.
Any help would be appreciated. Thanks. [import]uid: 10389 topic_id: 11776 reply_id: 311776[/import]

I tried adding in this code found elsewhere on the forum:

local function angleBetweenPoints ( srcObjx, srcObjy, dstObjx, dstObjy )  
 -- make sure we never return -1.#IND if we try to find angle between identical points  
 if ( srcObjx == dstObjx and srcObjy == srcObjy ) then return 0 end  
   
 -- Original angleBetween  
 local xDist = dstObjx - srcObjx ; local yDist = dstObjy - srcObjy  
 local angleBetween = math.deg( math.atan( yDist / xDist ) )  
 if ( srcObjx \< dstObjx ) then angleBetween = angleBetween + 90 else angleBetween = angleBetween - 90 end  
   
 -- These tend to get flipped around, this is a quick fix  
 if ( angleBetween == 0 ) then angleBetween = -180  
 elseif ( angleBetween == -180 ) then angleBetween = 0  
 end  
 return angleBetween  
end  

and

angleBetween = math.ceil( angleBetweenPoints (myObject.nextX,myObject.nextY , myObject.x, myObject.y) ) +180  

but it still wobbles and spins wildly at times

Angle = 277
Angle = 27
Angle = 27
Angle = 10
Angle = 15
Angle = 27
Angle = 27
Angle = 334
Angle = 334

[import]uid: 10389 topic_id: 11776 reply_id: 42842[/import]

 local PIE = 3.14159265358  
  
 local angle = math.atan2( p.y - prevY, p.x - prevX)  
 angle = angle \* 180 / PIE  
  
 plane:rotate(angle-prevAngle);  
  
  
 prevAngle = angle;  

for PI you can also use

math.pi   

[import]uid: 24 topic_id: 11776 reply_id: 42932[/import]

Rad! Thanks Carlos! Your PIE rules! [import]uid: 11636 topic_id: 11776 reply_id: 42936[/import]

assuming that it worked :slight_smile:

c. [import]uid: 24 topic_id: 11776 reply_id: 42942[/import]

Well Martian Control uses math.pi so it doesn’t really but thanks anyway :wink: [import]uid: 10389 topic_id: 11776 reply_id: 42947[/import]

look at flight path is in github too

c. [import]uid: 24 topic_id: 11776 reply_id: 42948[/import]

Yeah I saw that. I want to have multiple destinations a’la Martian Control and not landing strips. I’m not sure how compatible FP is with adapting to that nor how easy but will have another look.
MC has everything I need set up the way I designed the game idea about a year ago. [import]uid: 10389 topic_id: 11776 reply_id: 42959[/import]

put your rotation code or send it so ic an take a look

simple as possible

c. [import]uid: 24 topic_id: 11776 reply_id: 42960[/import]

Thanks, Carlos!
Well the rotation code is the same in Martian Control. [import]uid: 10389 topic_id: 11776 reply_id: 42962[/import]

I compared it to code on other websites for rotation and it seems sound but for some reason it goes weird. [import]uid: 10389 topic_id: 11776 reply_id: 42965[/import]

I downloaded the Flight Path code last night.
It doesn’t support iPad. It only has one location to land. It doesn’t flash the required landing location and I compiled it and installed it on my iPad which has iOS 5b2 and all I get is a black screen, whereas MC works fine. [import]uid: 10389 topic_id: 11776 reply_id: 43105[/import]

Echo [import]uid: 10389 topic_id: 11776 reply_id: 49668[/import]