Author Topic: circle_movement:set_initial_angle() problem ?  (Read 1389 times)

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
circle_movement:set_initial_angle() problem ?
« on: March 18, 2016, 11:22:49 am »
Hi.

I was making an event with a circle movement.
However, this movement need to start at a precise angle, so at first I tried math.pi / 2 in set_initial_angle() but it always start at the right
I also tried something based on http://math.rice.edu/~pcmi/sphere/drg_txt.html but nothing seems to happen, it always start at the right

This is the movement code

Code: (lua) [Select]

  local s = sol.movement.create("straight")
  s:set_angle(math.pi / 2)
  s:set_speed(60)
  s:set_max_distance(16)
  s:start(entity_sprite, function()
    local c = sol.movement.create("circle")
c:set_initial_angle(math.pi / 2) -- start the movement from above the hero's head -- looks like it is faulty ?
c:set_center(self, 0, -8)
c:set_clockwise(false)
c:set_max_rotations(2)
c:set_radius(16)
c:set_radius_speed(16)
c:set_duration(1250)
    c:start(entity_sprite)
  end)

Is this a bug or am I doing it wrong ?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #1 on: March 18, 2016, 11:39:02 am »

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #2 on: March 18, 2016, 11:46:28 am »
Oh then thanks for pointing the bug, I didn't checked the issue tracking before posting this thread

Diarandor

  • Hero Member
  • *****
  • Posts: 1045
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #3 on: March 18, 2016, 02:38:13 pm »
@MetalZelda: you can always use pixel movements (combined with some trigonometric or polynomial functions) to define a circle movement and other more complex movements.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #4 on: March 18, 2016, 03:46:43 pm »
I found a way to hide the issue with some effects (in the second part) using the same movements by randomly generating positions to a custom entity relative to the parent's entity position, kinda like a particle system. And the particles nicely hide the issue

This is pretty simple yet but it works

« Last Edit: March 18, 2016, 03:53:19 pm by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 1045
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #5 on: March 18, 2016, 04:29:33 pm »
MetalZelda: It is really nice your animation  ;D.
You can still combine your random movement with a circle movement, if you want more precision. For instance, you could use something like this (the code is untested, so it can surely be improved and there might be mistakes):
Code: (Lua) [Select]
local cx, cy = hero:get_position() -- Define center position here.
local r = 8 -- Define circle radius here (in pixels).
local angular_speed = 2*math.pi/1000 -- In radians per millisecond (it can be negative).
local init_angle = math.pi/2 -- Initial angle.
-- Function to return position for each time instant.
-- (Time variable must be given in milliseconds.)
local function f(t)
  local angle = init_angle + t*angular_speed
  local x = cx + r*math.cos(angle) 
  local y = cy + r*math.sin(angle)
  return math.floor(x), math.floor(y)
end
You can call that function from a timer looped each millisecond, which changes the position of the moving magic.
For more customization, you can define a function that modifies the radius and the angular speed depending on the time, make the angular movement accelerate/decelerate, or whatever you can imagine.
« Last Edit: March 18, 2016, 04:32:23 pm by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: circle_movement:set_initial_angle() problem ?
« Reply #6 on: March 18, 2016, 04:37:30 pm »
Oh yes, that's clever, I'm gonna try this