Log In  

Anyone got a nice function(s) for having one object rotate around single point?

I've done a little digging but all the Lua stuff points to the math library which appears to be limited in P8...

Appreciate any code or links.

P#20320 2016-05-08 15:17 ( Edited 2016-05-10 19:20)

Here you go:

direction = 0
anchor_sine = 0
anchor_x = 64

function _update()
  direction += .05
  anchor_sine += .01
  anchor_x = 64 + sin(anchor_sine) * 40
end

function _draw()
  cls()
  circfill(anchor_x, 64, 1.5, 7)
  circfill(anchor_x + cos(direction) * 10, 64 - sin(direction) * 10, 1.5, 8)
  circfill(anchor_x + cos(direction / 2) * 20, 64 - sin(direction / 2) * 20, 1.5, 9)
end
  • Blokatt
P#20321 2016-05-08 15:52 ( Edited 2016-05-08 20:05)

Awesome, thanks so much!

P#20324 2016-05-08 16:23 ( Edited 2016-05-08 20:23)

No problem!

P#20327 2016-05-08 17:32 ( Edited 2016-05-08 21:32)

Pasted it all in and worked great...wasn't even expecting the moving anchor, pretty sweet. But wasn't exactly sure what all the variables controlled, so I annotated it some more with extra variables. Thanks again!

anchor_sine=0
anchor_x=64
anchor_y=64
speed=.05
radius=20
ccw=false --counterclockwise?
direction=0 --leave at zero

function _update()
  anchor_sine += .01
  anchor_x = anchor_y + sin(anchor_sine) * 40 --this is speed/distance of anchor movement
end

function _draw()
  cls()

  --center point
  circfill(anchor_x, anchor_y, 1.5, 7)

  --get direction based on flag
  if (ccw) then 
    direction -= speed --counterclockwise
  else
    direction += speed --clockwise
  end

  --orbiting circle

  circfill(anchor_x + cos(direction / (radius/10)) * radius, anchor_y - sin(direction / (radius/10)) * radius, 1.5, 9)
end
P#20339 2016-05-08 20:48 ( Edited 2016-05-09 00:48)

By the way, you might want to use "+ sin" instead, since it's inverted in Lua.

P#20358 2016-05-09 12:46 ( Edited 2016-05-09 16:46)

[Please log in to post a comment]