Problem with certain movement [SOLVED]

Started by slufan, Tue 05/11/2019 12:33:56

Previous topic - Next topic

slufan

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

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

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.

Khris

You need to change the coordinates after the animation:

Code: ags
      cSpider.x += 50;  // move cSpider 50 pixels to the right instantly

slufan

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.

eri0o

This may be a case where it makes sense to share a video capture of this scene (either in YouTube, or Streamable)

Cassiebsg

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.
There are those who believe that life here began out there...

Khris

slufan, can you show us the frames of the animation? Does the anchor point move back from frame to frame?

slufan

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.


Khris

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?

slufan

Ok, here is the final result

With the "animate" code, of course with the cSpider.x +=50 line added.



With the "walk" code


How can I upload my sprites so you can see it?

Khris

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).
Code: ags
      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.

slufan

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

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(); 
    }
}



SMF spam blocked by CleanTalk