Solarus-Games English Forum

Solarus => Bugs & Feature requests => Topic started by: MetalZelda on March 18, 2016, 11:22:49 AM

Title: circle_movement:set_initial_angle() problem ?
Post by: MetalZelda 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 ?
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: Christopho on March 18, 2016, 11:39:02 AM
This is a known bug yes: https://github.com/christopho/solarus/issues/721
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: MetalZelda 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
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: Diarandor 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.
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: MetalZelda 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

(http://i.imgur.com/wtotIIA.gif)
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: Diarandor 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.
Title: Re: circle_movement:set_initial_angle() problem ?
Post by: MetalZelda on March 18, 2016, 04:37:30 PM
Oh yes, that's clever, I'm gonna try this