PDA

View Full Version : [AS2] Falling block Needs barriers


algar32
11-24-2010, 11:49 PM
I have a block. It falls from the sky. My character jumps on top of it. I want the character to not be able to pass through the left and right side of the block. Can you show me how to do this? (as of right now I dont have the falling script on the block, but i will)
Code ON BLOCK:
onClipEvent (enterFrame) {
if ((this.hitTest(this._parent.Char) && (this._parent.Char._y<258+this._height/2))) {
this._parent.Char._y=(_y-_height/2)-this._parent.Char._height/2
this._parent.Char.gravity = 0;
this._parent.Char.jump= 0;
}
//if (this.hitTest(this._parent.Char)){
// if(this._parent.Char._x>_x){
// this._parent.Char._x=_x+(_height/2)
// }
// if(this._parent.Char._x>_x){
// this._parent.Char._x=_x+(_height/2)
// }
// }
}
onClipEvent (load) {
var xspeed:Number = 0

}

Char stand for character...

As of right now only the top of the block works. You can walk and jump. I just want the left and right sides to be a barrier. Please help. Thanks.

Charak
11-24-2010, 11:56 PM
Well, What i would do anyways, is on that block, i would create 2 separate MCs that camouflage on the left and right sides, each having thier own AS, And i would do something alogn the lines of for the right/leftg mc shall we...

onClipEvent(enterframe) {
if(char.hitTest(this)) {

char._x +/- (depending on side) = 1

}
}

That way once he hit the side MC, he wouldnt be able to go any further... thats just the way i would do it anyways.. hope it helped!

algar32
11-25-2010, 12:06 AM
That actually made sense... .Thanks so much... You are saying go inside the block make two lines and movie clip them and put the move right move left hittest on them.... Thanks so much

algar32
11-25-2010, 12:49 AM
It sort of worked but its glitched.. I tried one and it passed right through so then I tried ten and that worked but it keeps it ten away from the line. I dont know what the best way to do this would be...

I hate hitTests in flash....

Charak
11-25-2010, 12:52 AM
Thicken up the lines! that should help! :D Flash does weird stuff when stuff is too thin

algar32
11-25-2010, 01:01 AM
Yah i Was just trying theckening the lines. It still only works if i set it as ten because my characters left movement is ten. It works but no matter where i move it It will not go exactly on the line of the block Its always too far left or right.

algar32
11-25-2010, 01:05 AM
If anyone has a project that they could upload in which a character can not pass through the walls of a block... I would be super happy...

Thanks for your help so far Charak.... Hopefully I can figure this out :)

algar32
11-25-2010, 01:58 AM
Yay I did it. .... thanks for your help


I wish flash had a simpler way to do this though

algar32
11-25-2010, 02:11 AM
Ok So the block works
but I want the lines to stay with the block when I move it around or when it respawns.... SO i put it in a movieclip... Well when I do this the code stops working. Is there anyway to make them stay together forever without experiencing this mishap?

algar32
11-25-2010, 02:13 AM
I have a scrip that works but it is on 2 lines and a square. i want these three items to stay together when they are moved or when they respawn

So to solve this, i put it in a movieclip... Well when I did this the code stops working. Is there anyway to make them stay together forever without experiencing this mishap?

Charak
11-25-2010, 02:16 AM
take them out of the movie clip, and position the centers just right so that they allign and use this simple code


this._x = blockmc._x
this._y = blockmc._y

algar32
11-25-2010, 03:56 AM
ok thanks I was hoping i could just throw em in a movie clip but that will work
thanks

algar32
11-25-2010, 03:51 PM
Ok it sort of worsk but it still gets through the line on the right side a little bit more than the one on the left. I have tried moving the lines and the blocks but nothing seems to get it just right.

What should I do?

Here is an swf....
It gets through a little on the right side... Is flash just not functioning properly or is there any way I can avoid this?

algar32
11-25-2010, 04:28 PM
also this code did not work for the moving block

this._x = block._x
this._y = block._y