Making an object move on a set pattern

Hello, I’m totally new to Lua, Game or Corona development, so I’m feeling really lost. My game is a top down stealth game, where a character needs to reach a goal area while collision with enemies…

The issue is, that I honestly have no clue how to implement a movement that keeps looping itself, like a patrol…would anyone have any idea?

Thanks in advance!

https://github.com/GabrielForLima/ColaTheGame

If your game is tile based you could store the tiles an NPC can use and get that character to navigate on only it’s allowable tiles. Let’s say you have a 2x3 area it is guarding. You define all the tiles around it that are traversable and it will be simple to make that character follow that path.

Hmm, Tiles? I’m not sure I didn’t really plan on it being grid based…could I have an example if it would not be asking too much?

Hi @Fire_Ware,

Another way would be to set up a series of transitions, and each on has an “onComplete” flag which triggers the next one in the sequence. This way, you could set up a repeating “patrol” pattern, start the character going, and it would repeat until you told it to stop.

https://docs.coronalabs.com/guide/media/transitionLib/index.html

Best regards,

Brent

I’ll try that one tomorrow, thanks!

Now my issue is that sometimes, the OnComplete will not entirely function. It seems to function only as long as the function is immediatly above the one it is calling…

local function moverrodar() transition.to (fiscal, {time= 1000, rotation=90, onComplete= moverx}) end local function moverx() transition.to (fiscal, {time= 4000, x=\_W - 150, onComplete= moverrodar}) end local function moverinicial() transition.to(fiscal, {time = 4000, y=100, onComplete=moverrodar}) end moverinicial()

Do I need to fit them all within a scope?

This will cause your NPC to move in a loop

local function moveNPC() transition.to (fiscal, {time= 4000, x=\_W + 150}) transition.to (fiscal, {delay=4000, time=4000, y=\_H - 150}) transition.to (fiscal, {time= 8000, x=\_W - 150}) transition.to (fiscal, {delay=12000, time=4000, y=\_H + 150}) timer.performWithDelay(16000, moveNPC) end moveNPC()

Be advised this is not very extendable and you will run into issues later on.

My advice is to make your NPCs autonomous and able to adapt but this goes way beyond the scope of this forum…

Without exception… all 2D games will use a tile-based layout to track all objects and where they are.  This enables you to use path finding algorithms to move entities in your game.   More info here

Yeah, I figure it will get more complicated as I think of more elaborate patterns.

But then I would need an actual AI, and SimpleAI only works on platformers, so I’ll simply need to get what I can, thanks a lot adrian trying it now.

Edit: Tiled, huh? Well, worth a check I suppose!

If your game is tile based you could store the tiles an NPC can use and get that character to navigate on only it’s allowable tiles. Let’s say you have a 2x3 area it is guarding. You define all the tiles around it that are traversable and it will be simple to make that character follow that path.

Hmm, Tiles? I’m not sure I didn’t really plan on it being grid based…could I have an example if it would not be asking too much?

Hi @Fire_Ware,

Another way would be to set up a series of transitions, and each on has an “onComplete” flag which triggers the next one in the sequence. This way, you could set up a repeating “patrol” pattern, start the character going, and it would repeat until you told it to stop.

https://docs.coronalabs.com/guide/media/transitionLib/index.html

Best regards,

Brent

I’ll try that one tomorrow, thanks!

Now my issue is that sometimes, the OnComplete will not entirely function. It seems to function only as long as the function is immediatly above the one it is calling…

local function moverrodar() transition.to (fiscal, {time= 1000, rotation=90, onComplete= moverx}) end local function moverx() transition.to (fiscal, {time= 4000, x=\_W - 150, onComplete= moverrodar}) end local function moverinicial() transition.to(fiscal, {time = 4000, y=100, onComplete=moverrodar}) end moverinicial()

Do I need to fit them all within a scope?

This will cause your NPC to move in a loop

local function moveNPC() transition.to (fiscal, {time= 4000, x=\_W + 150}) transition.to (fiscal, {delay=4000, time=4000, y=\_H - 150}) transition.to (fiscal, {time= 8000, x=\_W - 150}) transition.to (fiscal, {delay=12000, time=4000, y=\_H + 150}) timer.performWithDelay(16000, moveNPC) end moveNPC()

Be advised this is not very extendable and you will run into issues later on.

My advice is to make your NPCs autonomous and able to adapt but this goes way beyond the scope of this forum…

Without exception… all 2D games will use a tile-based layout to track all objects and where they are.  This enables you to use path finding algorithms to move entities in your game.   More info here

Yeah, I figure it will get more complicated as I think of more elaborate patterns.

But then I would need an actual AI, and SimpleAI only works on platformers, so I’ll simply need to get what I can, thanks a lot adrian trying it now.

Edit: Tiled, huh? Well, worth a check I suppose!