Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-24-2010, 11:49 PM   #1
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default [AS2] Falling block Needs barriers

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.
algar32 is offline   Reply With Quote
Old 11-24-2010, 11:56 PM   #2
Charak
Registered User
 
Join Date: Nov 2010
Posts: 5
Default

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!
Charak is offline   Reply With Quote
Old 11-25-2010, 12:06 AM   #3
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

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 is offline   Reply With Quote
Old 11-25-2010, 12:49 AM   #4
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

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....
algar32 is offline   Reply With Quote
Old 11-25-2010, 12:52 AM   #5
Charak
Registered User
 
Join Date: Nov 2010
Posts: 5
Default

Thicken up the lines! that should help! Flash does weird stuff when stuff is too thin
Charak is offline   Reply With Quote
Old 11-25-2010, 01:01 AM   #6
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

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 is offline   Reply With Quote
Old 11-25-2010, 01:05 AM   #7
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

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 is offline   Reply With Quote
Old 11-25-2010, 01:58 AM   #8
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

Yay I did it. .... thanks for your help


I wish flash had a simpler way to do this though
algar32 is offline   Reply With Quote
Old 11-25-2010, 02:11 AM   #9
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Default

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 is offline   Reply With Quote
Old 11-25-2010, 02:13 AM   #10
algar32
Senior Member
 
Join Date: Oct 2010
Posts: 116
Exclamation Coded objects placed in movieclip stopped working...

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?
algar32 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:55 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.