Be a Supporter!

AS2 Help Please

  • 216 Views
  • 5 Replies
New Topic Respond to this Topic
captinx
captinx
  • Member since: Feb. 15, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
AS2 Help Please 2009-05-28 12:59:52 Reply

Hi,

I am making a game don't really need to go into much detail about the game but im trying to make a wall that if the player (its a square)

is bigger than i certain height wont be able to go thought then when it becomes bellow the height it can go thought it.
so here is the AS2

onClipEvent (enterFrame) {
	if (this.hitTest(_root.player1 && _root.player1._height>13)) {
		
_root.player1._x -= _root.player1.Pspeed;

	} else {

	}
}

so its the normal hitTest thing and it works fine if you remove the "&& _root.player1._height>13" but im not sure if thats how you are ment to write it out for the height.

Thanks
Eli


| How long is a peace of string?

BBS Signature
WhoknowsmeaUdiO
WhoknowsmeaUdiO
  • Member since: Apr. 11, 2007
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS2 Help Please 2009-05-28 13:06:31 Reply

At 5/28/09 12:59 PM, captinx wrote: Hi,

I am making a game don't really need to go into much detail about the game but im trying to make a wall that if the player (its a square)

is bigger than i certain height wont be able to go thought then when it becomes bellow the height it can go thought it.
so here is the AS2

onClipEvent (enterFrame) {
if (this.hitTest(_root.player1 && _root.player1._height>13)) {

_root.player1._x -= _root.player1.Pspeed;

} else {

}
}

so its the normal hitTest thing and it works fine if you remove the "&& _root.player1._height>13" but im not sure if thats how you are ment to write it out for the height.

Thanks
Eli

Try:

onClipEvent (enterFrame) {
 	if (this.hitTest(_root.player1) && _root.player1._height>13)) {
 		
 _root.player1._x -= _root.player1.Pspeed;
 
 	} else {
 //nothing, that makes it just go through.
}
}

In case you haven't noticed yet, this isn't my main anymore. PM me here.

BBS Signature
51lver
51lver
  • Member since: Jan. 14, 2008
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS2 Help Please 2009-05-28 13:09:11 Reply

At 5/28/09 12:59 PM, captinx wrote: onClipEvent (enterFrame) {
if (this.hitTest(_root.player1 && _root.player1._height>13)) {

_root.player1._x -= _root.player1.Pspeed;

} else {

}
}

try:

onClipEvent (enterFrame) {
	if (this.hitTest(_root.player1) && _root.player1._height>13) {	
                 _root.player1._x -= _root.player1.Pspeed;
 	}
}

you need to split up the hitTest and the inequality

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS2 Help Please 2009-05-28 13:10:12 Reply

At 5/28/09 12:59 PM, captinx wrote: onClipEvent (enterFrame) {
if (this.hitTest(_root.player1 && _root.player1._height>13)) {

_root.player1._x -= _root.player1.Pspeed;

} else {

}
}

Almost - you need to close the parentheses for your hitTest -

if (hitTest(_root.player1) && _root.player1._height>13) {

You've got two different conditions - the hitTest and the check on your height. The comparison needs to be between the two conditions - you had it inside one. I'm explaining this badly :/

Also, I'd reccomend using a while loop to move your player back, since it allows for both smoother pushing back and generalisation to irregular surfaces:

if (hitTest(_root.player1._x - 10, _root.player1._y, true) && _root.player1._height>13) {
  do{
    _root.player1.x ++;
  } while(hitTest(_root.player1._x - 10, _root.player1._y, true));
};

I'd also reccomend against using the _height property to determine things since it's vulnerable to bugs and scaling e.t.c. You can give your guy a property or something to determine if he's big or not:

guy.isSmall = false;
if(...  && guy.isSmall)

BBS Signature
ColdLogic
ColdLogic
  • Member since: Nov. 12, 2003
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to AS2 Help Please 2009-05-28 13:10:47 Reply

if (this.hitTest(_root.player1 && _root.player1._height>13)) {

if(this.hitTest(_root.player1) && _root.player1._height > 13) {

captinx
captinx
  • Member since: Feb. 15, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS2 Help Please 2009-05-28 14:10:03 Reply

Thanks guys for your fast replys.

They all worked fine :)


| How long is a peace of string?

BBS Signature