(Solved) Animation restarting when i walk or leave region

Started by actaria, Sun 14/08/2022 16:00:04

Previous topic - Next topic

actaria

Hello,
I hope eveyone is enjoying Sunday.

I am actually stuck on a problem.
I made a wolf that animate when i "walk into a region" in front of him




The problem is that when i walk out of the region the animation is launching again and if i go back into the region it will restart the animation again.

I would like that the animation can not be started again until it has been fully played and reached the end of the loop.

My code is the classic one:

Code: ags

function region1_WalksOnto()
{
object[owolf].SetView(10);
object[owolf].Animate(0, 1, eOnce, eNoBlock);
}


Unfortunately i have no idea on how do to that.
Or maybe there's another way to do it ?

Any help would be appreciated, thanks a lot in advance. :)






eri0o

Is there any reason why you chose the animation to be non-blocking in this case? (using the eNoBlock parameter in you Animate function call)

actaria

Thanks a lot for the answer.

I choosed NonBlocking so the character can still move while the wolf is animated.

Am i wrong ? maybe there is something i am not understanding the right way ?


eri0o

#3
I don't understand why you use object[wolf] in your code, you can directly use oWolf or whatever the name you used in it, without using the object array...

The way I would do the animation for this would be handling two main states

resting (0) -> howling (2)

and adding transitions between these

resting (0) -> prepare (1) -> howling (2) -> retreat (3) -> resting (0)

then handling as such


  • state is resting (0) + player enters the region -> prepare (1) animation starts playing
  • state is prepare (1) and reached last frame -> howling (2) loops
  • state is howling (2) and player is away -> retreat (3) starts playing
  • state is retreat (3) and reached last frame -> resting (0) loops

you can do this in any other way, possibly also skipping the retreat animation if wanted. Then the actual implementation is however you would like - on the room you can check thing on repexec, rep exec always or something else. I find these looped checks in room script usually the easy way to go, since rooms usually have only a limited number of those, it's usually alright to run checks there as it's rare to have as much checks to impact performance.

actaria

Yes i am sorry this is because i translated my code from french "oloup" to english "wolf" i forgot about the "o".

Actually i have 2 animations:

1/Sitting and breathing

2/ going up, howl and sit back

I will do like you said with transitions with "prepare" and "retreat" see what i am able to do that way.

Thanks again for your help it's really appreciated.

Cassiebsg

Here's a quick suggestion:

1) Wolf is resting (player far away- eNoBlock)
2) Wolf goes up (player walks on to region - eOnce and eBlock)
3) Wolf howls (while player stands on region - eRepeate and eNoblock - you might have to check that the howl animation has ended before allowing it to restart)
4) Wolf sits back (player walks out of region by retreating - eOnce and eBlock + Wolf goes back to resting eRepeate and eNoblock)

Also what eri0o tried to say was that you don't need to type object[owolf].SetView(10) , do instead oloup.SetView(10).  :)
There are those who believe that life here began out there...

Rik_Vargard

Also, if you want this to happen only once, you can deactivate the region:

region [1].Enabled = false;

Khris

Not sure why the animation also restarts when you leave the area although you only used the "walks onto" event...?

Anyway, you can do  if (!oloup.Animating) ...  to only start the animation if the wolf isn't already animating. You can also move the SetView command to the room's "before fadein" event.

actaria

Thank you Cassiebsg
now i have all the steps and i should be able to do it properly.

"Also what eri0o tried to say was that you don't need to type object[owolf].SetView(10) , do instead oloup.SetView(10)."
O yes i understand now, i didn"t know that !

thanks also to you Rik_Vargard this is another nice suggestion by desactivate the region

"Not sure why the animation also restarts when you leave the area although you only used the "walks onto" event...?"
Yes Khris this is exactly my though and maybe i am crazy but yesterday the animation was not restarting when i was leaving the region.
I might i've done something.

I will remake the region from start.
and another great idea with the if (!oloup.Animating)

As usual you've all been so helpful... i don"t know what to say i am impressed each time.

Thank you all so much with all these solutions i might be able to do exactly what i wanted.

I will show the result when it's done  :)

actaria

Hello,

Since i am a lazy girl and beginner at coding i choosed Rik_Vargard solution using region

region [1].Enabled = false;

It works really well, thanks again everyone  :)




SMF spam blocked by CleanTalk