circle_movement:set_initial_angle() problem ?

Started by MetalZelda, March 18, 2016, 11:22:49 AM

Previous topic - Next topic
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 ?


Oh then thanks for pointing the bug, I didn't checked the issue tracking before posting this thread

@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."

March 18, 2016, 03:46:43 PM #4 Last Edit: March 18, 2016, 03:53:19 PM by MetalZelda
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


March 18, 2016, 04:29:33 PM #5 Last Edit: March 18, 2016, 04:32:23 PM by Diarandor
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.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."