SSK2: angleBetween documentation and samples

Per the documentation there are two options for angleBetween. 

math2d.angleBetween( v1, v2 )

math2d.angleBetween( x1, y1, x2, y2 )

Using SSK2 and NOT the math2d plugin ({ math2DPlugin = false }) 

It seems that per this doc you can pass it either 2 or 4 parameters, which I think is not correct.

Since the function has two parameters (function( vec1, vec2 )) I doubt that I can pass 4. This could however be a bad interpretation.

I have 2 sprites on screen (at random X/Y) and want to find the angle so I can put a sprite in between connecting them. Eg: Like a ladder, I am looking to determine the angle, and then I’ll rotate the sprite to match the angle.

(I’ll then probably use distanceBetween to change the length).

There isn’t a sample in SSK2 that uses angleBetween, and no actual examples in the doc other than the 2 lines above.  I did see some vector code and the below is an example of that, this causes an error per below.

local vec1 =  {grid[54].x,grid[54].y}local vec2 =  {grid[82].x,grid[82].y} print("XY:"..grid[54].x .. "|"..grid[54].y) print("XY:"..grid[82].x .. "|"..grid[82].y) myangle = ssk.math2d.angleBetween( vec1, vec2 ) print(myangle)

XY:490|350

XY:140|140

ERROR: Runtime error

ssk2/math2d.lua:419: attempt to perform arithmetic on field ‘x’ (a nil value)

I’m sure I’ve overlooked something simple, but with the docs and working through tests like the above, I can’t seem to come up with it.

Thoughts?

OK, so I solved it potentially a lot easier than how I was trying to! A one liner (Thanks to SSK2 Pro).

ssk.actions.face( sprite, { target = grid[82] } )

Literally it was that easy. Although I am curious how to use ‘angleBetween’.

  1. I’m glad you found and used ssk.actions.face()  Be sure to give the action library a close look and peek at the validation samples.  I think you’ll be happy with the power of these functions.
  1. I have fixed the function to handle both signatures and it will be in the next release (coming Friday or sooner):

    local v1 = ssk.math2d.angle2Vector( -45, true ) local v2 = ssk.math2d.angle2Vector( 45, true ) print(ssk.math2d.angleBetween( v1, v2 )) print(ssk.math2d.angleBetween( v1.x, v1.y, v2.x, v2.y ))

  2. I’m working on some cool bonus materials for Pro, thus the delay since the last update.

:slight_smile:

OK, so I solved it potentially a lot easier than how I was trying to! A one liner (Thanks to SSK2 Pro).

ssk.actions.face( sprite, { target = grid[82] } )

Literally it was that easy. Although I am curious how to use ‘angleBetween’.

  1. I’m glad you found and used ssk.actions.face()  Be sure to give the action library a close look and peek at the validation samples.  I think you’ll be happy with the power of these functions.
  1. I have fixed the function to handle both signatures and it will be in the next release (coming Friday or sooner):

    local v1 = ssk.math2d.angle2Vector( -45, true ) local v2 = ssk.math2d.angle2Vector( 45, true ) print(ssk.math2d.angleBetween( v1, v2 )) print(ssk.math2d.angleBetween( v1.x, v1.y, v2.x, v2.y ))

  2. I’m working on some cool bonus materials for Pro, thus the delay since the last update.

:slight_smile: