Author Topic: Problem with certain movement [SOLVED]  (Read 188 times)

Problem with certain movement [SOLVED]
« on: 05 Nov 2019, 12:33 »
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: Adventure Game Studio
  1. if(UsedAction(eGA_UseInv)) {
  2.     if (cSpider.ActiveInventory == iSpiderWeb) {
  3.       cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
  4.       cSpider.LockView(27);
  5.       cSpider.Animate(2, 5, eOnce, eBlock, eForwards);
  6.       cSpider.UnlockView();
  7.     }
  8. }
  9.  
This will make the move but when he finished the spider is in the same place.


Code: Adventure Game Studio
  1. if(UsedAction(eGA_UseInv)) {
  2.     if (cSpider.ActiveInventory == iSpiderWeb) {
  3.       cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
  4.       cSpider.ChangeView(27);
  5.       cSpider.Walk(220, 122, , eBlock, eAnywhere);
  6.     }
  7. }
  8.  
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.
« Last Edit: 07 Nov 2019, 17:00 by slufan »

Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Problem with certain movement
« Reply #1 on: 05 Nov 2019, 16:52 »
You need to change the coordinates after the animation:

Code: Adventure Game Studio
  1.       cSpider.x += 50;  // move cSpider 50 pixels to the right instantly
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Problem with certain movement
« Reply #2 on: 05 Nov 2019, 19:31 »
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.

Re: Problem with certain movement
« Reply #3 on: 05 Nov 2019, 20:54 »
This may be a case where it makes sense to share a video capture of this scene (either in YouTube, or Streamable)

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Problem with certain movement
« Reply #4 on: 05 Nov 2019, 22:22 »
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

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Problem with certain movement
« Reply #5 on: 06 Nov 2019, 00:35 »
slufan, can you show us the frames of the animation? Does the anchor point move back from frame to frame?
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Problem with certain movement
« Reply #6 on: 06 Nov 2019, 13:38 »
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

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Problem with certain movement
« Reply #7 on: 06 Nov 2019, 14:03 »
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
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?
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Problem with certain movement
« Reply #8 on: 06 Nov 2019, 15:10 »
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

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Problem with certain movement
« Reply #9 on: 06 Nov 2019, 16:33 »
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: Adventure Game Studio
  1.       cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
  2.       cSpider.ChangeView(27);  // you can use the view's name constant instead of 27, like SPIDERSWING
  3.       cSpider.Walk(cSpider.x + 30, cSpider.y, eBlock, eAnywhere);

I've used 30 here, try experimenting with the distance until it fits exactly.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Problem with certain movement
« Reply #10 on: 07 Nov 2019, 17:00 »
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: Adventure Game Studio
  1. if(UsedAction(eGA_UseInv)) {
  2.     if (cSpider.ActiveInventory == iSpiderWeb) {
  3.       cSpider.Walk(113, 132,  eBlock, eWalkableAreas);
  4.       cSpider.LockView(27);
  5.       cSpider.x+=30;  // To match the walk sprite
  6.       cSpider.Animate(2, 5, eOnce, eBlock, eForwards);
  7.       cSpider.UnlockView();
  8.     }
  9. }
  10.  
  11.  
  12.