Page 1 of 1

Key disable&Gravity Set!

PostPosted: Mon Mar 07, 2011 9:07 am
by XclusiveGames
if a actor's key down(up) is set to y = y -9; it should fly when we press the given button.how to disable the key
when it collides with another character ,and the character should have gravity so that it will fall to the ground.any idea! please? :?

Re: Key disable&Gravity Set!

PostPosted: Mon Mar 07, 2011 9:14 am
by skydereign
To do that you need a variable. I'd suggest you create a variable that holds the state of the actor (state).
actor -> KeyDown (up, Repeat) -> Script Editor
Code: Select all
if(state==0)
{
    y=y-9;
}


The above says only when state is zero do you have the actor fly. So, if you want to disable the flying ability, set it to 1.
actor -> Collision (otherActor) -> Script Editor
Code: Select all
state=1;


Now flying will be disabled. I assume you want to enable it as soon as you touch back on ground, so in your collision with top side of the ground actor, add this.
Code: Select all
state=0;


This type of variable control will help a lot, when making a game. The idea is pretty simple and very powerful. If you understand this, then you can have many different values for the state variable, and control the actor very precisely.

Re: Key disable&Gravity Set!

PostPosted: Mon Mar 07, 2011 9:27 am
by XclusiveGames
Thanks SKI it worked.
:D