Solarus-Games English Forum

Solarus => Bugs & Feature requests => Topic started by: llamazing on September 08, 2017, 07:31:41 AM

Title: Straight movement bug with set_max_distance?
Post by: llamazing on September 08, 2017, 07:31:41 AM
I'm trying to use a straight movement, and the straight_movement:set_max_distance(max_distance) function is not working the way that I'd expect.

Below is simplified code of what I am trying to do. At 4 seconds the table obj is moved 100 pixels to the right, and then 3 seconds after that it is moved 100 pixels to the left to return it to its original position.

The problem is that the set_max_distance function appears to be calculating the distance from (0,0), when I'd expect it to calculate the distance from what the coordinates were at the start of the movement. The result is that the second movement ends up being a 200 pixel movement to the left instead of the 100 pixels that I wanted (the object stops when x=-100, which is 100 pixels from (0,0)).

Code ( lua) Select
local obj = {x=0, y=0}
sol.timer.start(4000, function()
  print(obj.x) --0 at 4 seconds
 
  local movt1 = sol.movement.create"straight"
  movt1:set_speed(100)
  movt1:set_angle(0)
  movt1:set_max_distance(100)
  movt1:start(obj)
 
  function movt1:on_finished() print(obj.x) end --obj.x=100 at 5 seconds
 
  sol.timer.start(3000, function()
    print(obj.x) --100 at 7 seconds
   
    local movt2 = sol.movement.create"straight"
    movt2:set_speed(100)
    movt2:set_angle(math.pi)
    movt2:set_max_distance(100)
    movt2:start(obj)
   
    function movt2:on_finished() print(obj.x) end --obj.x=-100 at 9 seconds; expected obj.x=0 at 8 seconds
  end)
end)
Title: Re: Straight movement bug with set_max_distance?
Post by: Christopho on September 08, 2017, 08:58:35 AM
It looks like a bug to me. Can you report it on https://github.com/solarus-games/solarus/issues/new?
I will fix this for 1.6.
Title: Re: Straight movement bug with set_max_distance?
Post by: llamazing on September 08, 2017, 02:56:26 PM
Issue 1075 (https://github.com/solarus-games/solarus/issues/1075) created