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
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 ?
This is a known bug yes: https://github.com/christopho/solarus/issues/721
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.
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
(http://i.imgur.com/wtotIIA.gif)
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):
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.
Oh yes, that's clever, I'm gonna try this