I am having trouble with this because my npc is not making a circle movement. I want the NPC (gerf) to circle around a entity (chest1).
local circle = sol.movement.create("circle")
circle:set_center(chest1,248,357)
circle:start(gerf)
Did you try to add the remaining properties (radius, angle speed, etc) before starting the movement?
I think the Lua API should give an example for each movement.
It is still just standing there. No error outputs.
local circle = sol.movement.create("circle")
circle:set_center(chest1,248,357)
circle:set_loop_delay(2000)
circle:set_angle_speed(200)
circle:set_duration(2000)
circle:set_max_rotations(10)
circle:set_initial_angle(360)
circle:set_clockwise(true)
circle:set_radius(360)
circle:set_radius_speed(60)
circle:start(gerf)
This is weird. Does it happen with other types of movements? And are you sure this code is being called? Maybe posting all the code of the script will help.
Also, make sure that your NPC is not initially stuck in a wall, heheh. :P
The NPC works with random_path and jump, so it is not stuck.
Full code:
local map = ...
local game = map:get_game()
local hero = map:get_hero()
function map:on_started()
local circle = sol.movement.create("circle")
circle:set_center(chest1,248,357)
circle:set_loop_delay(2000)
circle:set_angle_speed(200)
circle:set_duration(2000)
circle:set_max_rotations(10)
circle:set_initial_angle(360)
circle:set_clockwise(true)
circle:set_radius(360)
circle:set_radius_speed(60)
circle:start(gerf)
end
The only time anything happens is when I do the following.
local map = ...
local game = map:get_game()
local hero = map:get_hero()
function map:on_started()
local circle = sol.movement.create("circle")
circle:set_radius(360)
circle:start(gerf)
end
No idea of what is wrong. A workaround is to use a custom entity (I recommend to make it traversable) and code the movement. Idea of how to do it:
local x, y
local r, a, t -- radius, angle, time
and in a timer that increments the angle by t:
local a = a0 + t
x = x0 + r * cos(a)
y = y0 + r * sin(a)
The remaining details are a programming exercise for you :)
So is this a bug?
I don't think that script is going to do what you want it to do.
circle:set_center(chest1,248,357)
You are setting the center point of the circle 248 pixels horizontally and 357 pixels vertically away from the chest (i.e. 434 pixels away from the chest in total).
With a radius of 360 pixels, your NPC will not be circling the chest. My guess is the reason the script is not working is because the path you've given the NPC takes it beyond the borders of the map? Hard to say without actually seeing your map.
Have you tried just this?
circle:set_center(chest1)
I agree with llamazing :D
llamazing is correct. I did that and changed my radius to 20. Is it possible to have the sprite use all 4 facing directions when going around an entity or would it be better to loop with the path movement?
local circle = sol.movement.create("circle")
circle:set_center(chest1)
circle:set_loop_delay(1000)
circle:set_angle_speed(100)
circle:set_duration(100)
circle:set_max_rotations(100)
circle:set_initial_angle(100)
circle:set_clockwise(true)
circle:set_radius(20)
circle:set_radius_speed(1)
circle:set_ignore_obstacles(true)
circle:start(gerf)
You can do it with both types of movements. Try to change the direction of the NPC if necessary, when some of these events are called: "entity:on_movement_changed(movement)" or "entity:on_position_changed(x, y, layer)".
I tried the following, but it did nothing. I normally would do this for an enemy to use the 4 way directions.
function gerf:on_movement_changed()
sprite:set_direction(movement:get_direction4())
end