So given the below situation, I want the sprites to meet at the target location, my code works but I don't understand something, at first they were going off in the wrong direction it seemed to be 90 degrees off so I minus the 90 and sure enough they go where I want them to ... but why?
Anyone good at Pythagorean theorem care to explain?
sx#=GetSpriteXByOffset(gAtom[atom_index].sprite_id)
sy#=GetSpriteYByOffset(gAtom[atom_index].sprite_id)
mx#=gAtom[atom_index].mergeX // target x
my#=gAtom[atom_index].mergeY // target y
a#=calculateAngle(sx#, sy#, mx#, my#)-90 // << here, why -90, whats wrong??
SetSpritePhysicsVelocity(gAtom[atom_index].sprite_id, cos(a#)*100, sin(a#)*100)
and the helper functions from UCF project
function calculateDistance(xPosition1#, yPosition1#, xPosition2#, yPosition2#)
distance# = 0
b# = 0
c# = 0
if xPosition1# > xPosition2#
b# = xPosition1# - xPosition2#
elseif xPosition1# < xPosition2#
b# = xPosition2# - xPosition1#
endif
if yPosition1# > yPosition2#
c# = yPosition1# - yPosition2#
elseif yPosition1# < yPosition2#
c# = yPosition2# - yPosition1#
endif
distance# = sqrt((b# * b#) + (c# * c#))
endfunction distance#
function calculateAngle(xPosition1#, yPosition1#, xPosition2#, yPosition2#)
distance# = calculateDistance(xPosition1#, yPosition1#, xPosition2#, yPosition2#)
angle# = 0
c# = 0
if yPosition1# > yPosition2#
c# = yPosition1# - yPosition2#
elseif yPosition1# < yPosition2#
c# = yPosition2# - yPosition1#
endif
if distance# > 0
angle# = ASin(c# / distance#)
endif
if xPosition1# = xPosition2# and yPosition1# < yPosition2#
angle# = 180
elseif xPosition1# = xPosition2# and yPosition1# > yPosition2#
angle# = 0
elseif xPosition1# < xPosition2# and yPosition1# = yPosition2#
angle# = 90
elseif xPosition1# > xPosition2# and yPosition1# = yPosition2#
angle# = 270
elseif xPosition1# > xPosition2# and yPosition1# < yPosition2#
angle# = 270 - angle#
elseif xPosition1# < xPosition2# and yPosition1# < yPosition2#
angle# = angle# + 90
elseif xPosition1# > xPosition2# and yPosition1# > yPosition2#
angle# = angle# + 270
elseif xPosition1# < xPosition2# and yPosition1# > yPosition2#
angle# = 90 - angle#
endif
endfunction angle#
Is it my code that's wrong or the helper functions, I thought I had a grip on the basics of pythag so I want to understand what's up here, yes it works but superglue and duct tape is not my style, not without some WD40 andway .. lol (engineers joke, if it moves and it shouldn't, duct tape, is it doesn't move and it should, WD40)