Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johanvepa on Mon 16/02/2015 20:14:30

Title: Walk backwards
Post by: johanvepa on Mon 16/02/2015 20:14:30
Is there a way to make a character walk backwards? That is, keep his current view, but reverse his direction and animation.
Title: Re: Walk backwards
Post by: Snarky on Mon 16/02/2015 20:19:31
No. The simplest way to do it is to create another view with the directions flipped and the animations reversed. It would also be possible to code a module to reverse the view (and flip the character orientation), but that's probably a bit beyond the Beginners' forum.
Title: Re: Walk backwards
Post by: selmiak on Mon 16/02/2015 20:20:34
if you want to save time when animating just click on every frame in the character's view and set flipped to true. Works best for left/right and not so good for up/down.
If you want to be able to flip a character's visible movement for gameplay or confusion just create a new view and switch the frames accordingly in the view and change the view ingame when needed.
Title: Re: Walk backwards
Post by: johanvepa on Mon 16/02/2015 20:33:59
Weeell, both solutions are of course simple and straightforward enough. Only I was hoping for something that would let me avoid doing that by instead using a not-so-custommade piece of coding  :-D

Anyway, It's back to the drawing board for me ;)
Title: Re: Walk backwards
Post by: Slasher on Mon 16/02/2015 20:44:31
Hi,

it would depend on how you want it applied.

in one room if char x = this:

Example I have used
Code (ags) Select

function room_RepExec()
{
if(cMazio.Room==10)
 
if(cConrad.x  >=  cMazio.x) // causes view to be 1 and walking backwards to right of screen
cConrad.Loop=1;

else if(cConrad.x < cMazio.x) // or just use else
cConrad.Loop=2;
}


Title: Re: Walk backwards
Post by: johanvepa on Mon 16/02/2015 20:50:11
Slasher, I  haven't tried out your code yet, but I am a bit confused as to why you set cConrad's LOOP to 1 or 2, I would expect his VIEW to be the key?

Title: Re: Walk backwards
Post by: Slasher on Mon 16/02/2015 20:54:41
Quote, but I am a bit confused as to why you set cConrad's LOOP to 1 or 2, I would expect his VIEW to be the key?
The players view is already determined in his properties: you are just manipulating his view loops.

In my example: if player is over another's chars x then he will turn to loop 1 and will walk backwards if you walk further to the right of other character's x and loop 2 if lower that chars x so you always face char. You may of course have a different condition.

I have this situation in a game and it works fine ;)



Title: Re: Walk backwards
Post by: monkey0506 on Mon 16/02/2015 22:15:06
Quote from: slasher on Mon 16/02/2015 20:44:31
Code (ags) Select
  if (cConrad.x >= cMazio.x) {}
  else if (cConrad.x < cMazio.x) {} // or just use else

The two conditions here are mutually exclusive. If one is true, then the other never can be (at that moment). Only one is true at a time, and it being true means that the other is false. You should never, ever, ever, ever, ever, ever do this. Ever.

If there is any possibility that one condition could change the state of cConrad.x or cMazio.x, then it might make sense to have a separate if-statement. But using else if to check the exact inverse of a condition is never right - that is what else means. If you want to add a note to yourself for added clarity, that is when you should add a comment.

Code (ags) Select
  if (cConrad.x >= cMazio.x) {}
  else {} // this MEANS that cConrad.x < cMazio.x!
Title: Re: Walk backwards
Post by: Slasher on Tue 17/02/2015 06:25:25
Yar, my slip up... Cheers Monkey ;)
Title: Re: Walk backwards
Post by: johanvepa on Fri 20/02/2015 20:34:03
i'll have to give this a few try-outs, I guess. Thank you for your suggestions everyone.