Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: pharlap on Sat 15/06/2013 09:26:31

Title: Movement detection? *SOLVED*
Post by: pharlap on Sat 15/06/2013 09:26:31
Hey all. Sorry to be a pest. This has vexed me on a few previous games I've made. Never found a good solution.

Essentially I am wanting to know if there is a functionality for detecting whether a non player character is moving or static.

I've tried a few clumsy solutions in the past.

At present, the player deals with NPCs who are possessed by demonic forces who like to crack out their telekinesis from time to time. I have rooms full of objects created as characters (chairs, tables, knives, pots and pans etc). Have set it so that at random intervals the possessed will hurl one of these objects telekinetic at the player. Easy enough. The character (chair, pot etc) projects from where it is to where the player is, non eblocked.

Problem is, I am wanting it to only inflict damage while in motion, not to cause damage if a player sprite collides with it when it is static.

In past games I've made with projectiles, I've rigged them with timers. Problem is if they land to close, they remain dangerous due to the timer status even when static until the timer runs down.

I am trying out a clumsy method at the moment whereby I establish multiple definable variables for each throwable thing. Example:

WHere cChair = the throwable chair character
Where Chaircurrentx =  the x position of the chair in the current loop
Where Chairpriorx= the x position of the chair in the previous loop
Where Chairmoving = an assessment as to whether or not the chair is moving

Chairpriorx=Chaircurrentx;
Chaircurrentx=cChair.x;

If (Chaircurrentx != Chairpriorx) Chairmoving=1;


THis isn't the exact script I've used for this. I dont have the internet at home so have come to an internet cafe to make this query. But I'm sure you all get the gist. The same tests are sett for Y variables too. Essentially each loop tests whether the co ordinates of the chair character are the same as the previous loop. If not, it returns a 1 to another variable that indicates that the chair is in motion. This will factor into another IF conditional statement which will lead into a damage assessment and infliction subroutine. etc.

Given that I intend to have situations with a great many objects that can be psychically thrown at the player, I was wondering if there was a less cumbersome method than replicating numerous variable sets for each throwable object?




Title: Re: Movement detection?
Post by: Khris on Sat 15/06/2013 11:09:54
You do know about Character.Moving, right?
Quotereadonly bool Character.Moving

Returns true if the character is currently moving, or false if not.
Title: Re: Movement detection?
Post by: Lewis on Sat 15/06/2013 11:21:20
Yeah, you'll want Character.Moving to check for that.

Code (AGS) Select
if cChair.Moving {
    //this is what it does
    }
Title: Re: Movement detection?
Post by: geork on Sat 15/06/2013 12:36:19
Sorry to be pedantic Lewis, but it's
Code (AGS) Select
if(cChar.Moving){
  //this is what it does
}

I know you already knew that, but I felt a bit mean today ;)
Title: Re: Movement detection?
Post by: Snarky on Sat 15/06/2013 14:01:41
You're wrong, geork. The character is called cChair, not cChar.
Title: Re: Movement detection?
Post by: Phemar on Sat 15/06/2013 18:26:22
But the brackets were still missing ;)
Title: Re: Movement detection?
Post by: geork on Sat 15/06/2013 18:46:14
QuoteYou're wrong, geork. The character is called cChair, not cChar.

AHH, I thought that was a typo :D

On the other hand, the irony is brilliant, so it all works out :P
Title: Re: Movement detection?
Post by: pharlap on Sun 16/06/2013 07:01:21
Holy crap. Many thanks my friends.

I had never found that functionality.

I have wasted many extra hours on several games coming up with many complicated ways to try to achieve what it appears this does in a straightforward manner.

Really appreciate your help.

I will try it out as soon as I get home tonight