Math question... offset spawned actor between 0,0 and another actor

BarkBarkCoBarkBarkCo Member Posts: 1,400
edited November -1 in Working with GS (Mac)
I have a ball that travels around the screen. If you draw an imaginary line from 0,0 to my ball actor, I need to spawn different actor 40 pixels below my ball, down that line... Does that make sense? I just need the math for positioning the second actor. Thanks!

Comments

  • ORBZORBZ Member Posts: 1,304
    x = (magnitude(ballX, ballY)-40)*cos(vectorToAngle(ballX, ballY))
    y = (magnitude(ballX, ballY)-40)*sin(vectorToAngle(ballX, ballY))

    note: this is simplified because your start point is 0,0

    if it were not 0, 0 you would compute the magnitude and the vectortoangle slightly differently: targetx - startx, targety - starty. But because startx and starty are 0 you can omit them from the equation.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    That didn't take long at all! Thanks for the tip for when 0,0 is not the starting point as ultimately I will need to move that around!

    ORBZ for moderator!!
Sign In or Register to comment.