Movement detection? *SOLVED*

Started by pharlap, Sat 15/06/2013 09:26:31

Previous topic - Next topic

pharlap

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?





Khris

You do know about Character.Moving, right?
Quotereadonly bool Character.Moving

Returns true if the character is currently moving, or false if not.

Lewis

Yeah, you'll want Character.Moving to check for that.

Code: AGS
if cChair.Moving {
    //this is what it does
    }
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

geork

Sorry to be pedantic Lewis, but it's
Code: AGS
if(cChar.Moving){
  //this is what it does
}

I know you already knew that, but I felt a bit mean today ;)

Snarky

You're wrong, geork. The character is called cChair, not cChar.

Phemar

But the brackets were still missing ;)

geork

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

pharlap

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

SMF spam blocked by CleanTalk