[Solved]How do I make a circle movement?

Started by zutokaza, April 02, 2017, 10:51:06 AM

Previous topic - Next topic
April 02, 2017, 10:51:06 AM Last Edit: May 06, 2017, 03:27:11 AM by zutokaza
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).

Code ( lua) Select
local circle = sol.movement.create("circle")
circle:set_center(chest1,248,357)
circle:start(gerf)

Solarus Works on ReactOS Opensource Windows OS

https://www.reactos.org/forum/viewtopic.php?f=2&t=14759&p=120616#p120616

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.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

It is still just standing there. No error outputs.

Code ( lua) Select
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)
Solarus Works on ReactOS Opensource Windows OS

https://www.reactos.org/forum/viewtopic.php?f=2&t=14759&p=120616#p120616

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.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Also, make sure that your NPC is not initially stuck in a wall, heheh. :P
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

The NPC works with random_path and jump, so it is not stuck.


Full code:
Code ( lua) Select
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.

Code ( lua) Select
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
Solarus Works on ReactOS Opensource Windows OS

https://www.reactos.org/forum/viewtopic.php?f=2&t=14759&p=120616#p120616

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 :)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."


I don't think that script is going to do what you want it to do.

Code (lua) Select
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?
Code (lua) Select
circle:set_center(chest1)

I agree with llamazing :D
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

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?

Code ( lua) Select
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)
Solarus Works on ReactOS Opensource Windows OS

https://www.reactos.org/forum/viewtopic.php?f=2&t=14759&p=120616#p120616

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)".
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I tried the following, but it did nothing. I normally would do this for an enemy to use the 4 way directions.

Code ( lua) Select
function gerf:on_movement_changed()

  sprite:set_direction(movement:get_direction4())
end
Solarus Works on ReactOS Opensource Windows OS

https://www.reactos.org/forum/viewtopic.php?f=2&t=14759&p=120616#p120616