Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: slufan on Tue 05/11/2019 12:33:56

Title: Problem with certain movement [SOLVED]
Post by: slufan on Tue 05/11/2019 12:33:56
Hello everyone

I have started with AGS a few days ago and I have a problem with one of my character movement. I've been trying to creat a game with and spider that swing over a serie of branches but I'm having problems with the movement.
The spider has his specific view to swing, but, or it makes the movement two, or three times, or when he stop stay at the same place where he started.

This is what I'm trying so far:

Code (ags) Select

if(UsedAction(eGA_UseInv)) {
    if (cSpider.ActiveInventory == iSpiderWeb) {
      cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
      cSpider.LockView(27);
      cSpider.Animate(2, 5, eOnce, eBlock, eForwards);
      cSpider.UnlockView();
    }
}

This will make the move but when he finished the spider is in the same place.


Code (ags) Select

if(UsedAction(eGA_UseInv)) {
    if (cSpider.ActiveInventory == iSpiderWeb) {
      cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
      cSpider.ChangeView(27);
      cSpider.Walk(220, 122, , eBlock, eAnywhere);
    }
}

This will move the character forward to his new position, but make the swing movement two or three times depending how far he gets.

I think there is the same movement using by Lucasarts in Fate Of Atlantis when Indy flys with his whip over a hole or something.
Any help will be highly appreciated.
Thanks in advance and sorry for my bad english, I'm from Spain.
Title: Re: Problem with certain movement
Post by: Khris on Tue 05/11/2019 16:52:06
You need to change the coordinates after the animation:

      cSpider.x += 50;  // move cSpider 50 pixels to the right instantly
Title: Re: Problem with certain movement
Post by: slufan on Tue 05/11/2019 19:31:20
Thank you Khris for your reply.

Ok, thats solve the problem of the final position, but the animation still plays in the same place, so when it finish the spider simply disappear from the start point and appear in the destination point.
Title: Re: Problem with certain movement
Post by: eri0o on Tue 05/11/2019 20:54:18
This may be a case where it makes sense to share a video capture of this scene (either in YouTube, or Streamable)
Title: Re: Problem with certain movement
Post by: Cassiebsg on Tue 05/11/2019 22:22:55
I think you have two choices. Either use the loop as a walking animation, and then AGS will move the figure for you, or you need to make your animation start in one point and end on the destination (the sprites animate with the displacement instead of in place) and then use Khris's code to get the normal spider in place.
Title: Re: Problem with certain movement
Post by: Khris on Wed 06/11/2019 00:35:11
slufan, can you show us the frames of the animation? Does the anchor point move back from frame to frame?
Title: Re: Problem with certain movement
Post by: slufan on Wed 06/11/2019 13:38:01
Thanks for all your responses.
The movement I try to reproduce is this, of course with and spider, not Indy, but the main concept is this.
I'll try to upload my own animation with the codes that I put in the first post so you can see the result.
As well the sprites Khris asked for it.

(https://i.imgur.com/Ctt9MNP.gif)
Title: Re: Problem with certain movement
Post by: Khris on Wed 06/11/2019 14:03:00
Right, so if your spider's swing animation is similar to Indy's, the first approach should work fine:
- walk to position
- potentially change x coordinate
- play swing animation once, blocking
- change x coordinate

You said
Quote from: slufan on Tue 05/11/2019 19:31:20
Ok, thats solve the problem of the final position, but the animation still plays in the same place, so when it finish the spider simply disappear from the start point and appear in the destination point.
Can you clarify how this approach doesn't work for you?
Title: Re: Problem with certain movement
Post by: slufan on Wed 06/11/2019 15:10:21
Ok, here is the final result

With the "animate" code, of course with the cSpider.x +=50 line added.
(https://i.imgur.com/t9kjfxj.gif)


With the "walk" code
(https://i.imgur.com/hAsgY4X.gif)

How can I upload my sprites so you can see it?
Title: Re: Problem with certain movement
Post by: Khris on Wed 06/11/2019 16:33:30
Ok, so the anchor point does change its position within the animation frames.
In that case you should use the 2nd approach, but you need to make sure the animation ends exactly at the right frame (i.e. find the correct x distance to walk).
      cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
      cSpider.ChangeView(27);  // you can use the view's name constant instead of 27, like SPIDERSWING
      cSpider.Walk(cSpider.x + 30, cSpider.y, eBlock, eAnywhere);


I've used 30 here, try experimenting with the distance until it fits exactly.
Title: Re: Problem with certain movement
Post by: slufan on Thu 07/11/2019 17:00:03
Ok, I think I have it.

The problem was that the sprite was not wide enough to reproduce the entire animation correctly. I have made a new sprite wider than the previous one and it works well.
However, a new problem arose, since the new sprite is wider than the previous one and wider than the normal sprite, when the animation began it moved 30 pixels to the left, but I solved it by instantly moving the spider those 30 pixels towards right and so I have solved it.
Maybe it is not be the best way to do it, but for me it's fine.
The final code is this, I put it in case someone else could serve.

Thanks to all who have help me, specially to Khris.

Code (ags) Select

if(UsedAction(eGA_UseInv)) {
    if (cSpider.ActiveInventory == iSpiderWeb) {
      cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
      cSpider.LockView(27);
      cSpider.x+=30;  // To match the walk sprite
      cSpider.Animate(2, 5, eOnce, eBlock, eForwards);
      cSpider.UnlockView();
    }
}