1

Is there a way to make a function that just adds motion to an object like the motion_add function from Game Maker?

Like: motion_add(speed1, direction1, speed2, direction2) ... where speed1 and direction1 is the current values of the object and speed2 and direction2 is the additive.

deepadmax
  • 73
  • 2
  • 7

1 Answers1

1

I've figured it out myself.

def CoordsToDir(x1, y1, x2, y2):
    return atan2(y2 - y1, x2 - x1)*180/pi

def DirToCoords(direction, length):
    return [cos((direction)  * pi / 180) * length, sin((direction)  * pi / 180) * length]

def motion_add(speed1, direction1, speed2, direction2):
    [x1, y1] = DirToCoords(direction1, speed1)
    [x2, y2] = map(sum, zip([x1, y1], DirToCoords(direction2, speed2)))
    speed = hypot(x2, y2)
    direction = CoordsToDir(0, 0, x2, y2)
    return [speed, direction]
Petah
  • 45,477
  • 28
  • 157
  • 213
deepadmax
  • 73
  • 2
  • 7