View Full Version : Problem with falling object not stopping
garlandpool
03-11-2008, 07:56 PM
I have this problem I can't seem to find a solution for. It's harder to explain than to just put up the fla file and have someone look at it. I usually just suffer in silence and then, perhaps months later figure it out. So I thought I might kill a few months by asking all the pro's around this forum.
Here's the swf to view:
http://www.rosettastoneofguitar.com/singapore/subLevel_simulation1.swf
Here's the fla to look inside, if you're interested:
http://www.rosettastoneofguitar.com/singapore/subLevel_simulation1.fla
I have created this falling rock symbol that falls when the player moves under it. What I would like to add, but can't seem to figure out, is how to make it then stop when it hits the walls of the cave below. If someone could take a look at it and then explain a work-around for what I want, I'd be very grateful.
I also have been wondering about the possible hang-ups of doing the loops the way I'm doing here. I'm starting to move more toward using functions and setInterval, but I'm not quite where I need to be yet to outpower my old way of doing things.
drumn4life0789
03-11-2008, 08:07 PM
search around for the hittest function. It should help you out. basically you have to do rock hittest if x and y are the same as some x and y of the wall then stop the fall. basically.
Durnus
03-11-2008, 08:58 PM
This is assuming you know a bit of actionscript:
if(wall.hitTest(rock._x, rock._y, true))
{
rock.yvel = 0; //Assuming you are doing a calculation, I'm at school so I can't open the flash file.
}
<is not pro yet though :(>
garlandpool
03-11-2008, 09:26 PM
Here is the line of code I have inside the falling rock.
if (_parent._parent.walls.hitTest(this._x, this._y, true)) {
trace("Hitting the wall now");
ySpeed=0;
}
The thing is, the rock is inside the caveWalls symbol. So, when I say _parent._parent.walls.hitTest... It thinks it's hitting the walls all the time. I put that trace statement in it to test for that. When I saw that message in the output window it explained why the rock stopped falling at all after I added this hitTest. For some reason it thinks it's hitting the walls, even though I'm using a shapeflag type hitTest and the rock is in an empty space between the cave walls.
The way I'm building this game, it will be way harder for me to code if I can't put the rocks inside the walls. If you open the fla, and look around, I'm sure you'll see why that would make my job so much harder. (By the way, the fla I've posted for anyone to download is just a dummy version of my file. I wanted to take out everything to minimize confusion...just my problem and some "dummy" elements involved are present.)
To put it in words, my entire level is like 10x smaller than everything else. I increase the size of it with some code just inside the symbol for the cave walls.
garlandpool
03-12-2008, 07:20 AM
Well, thanks very much to the couple of people who tried to help me. I'm glad noone got hurt, falling over eachother trying to figure out my problem. I guess I'm finally getting better at this flash coding stuff. In case it helps anyone else, here's the answer to my problem:
if (_parent.maze.hitTest(this._x * 10, this._y * 10, true)) {
ySpeed = 0;
}
The magic is in the part that says "this._x * 10" I had to put that in because I am scaling my levels from really tiny to 10X their normal size. It has plagued all my math and it seems it has manifested itself once again. Maybe I need to move away from that sort of level building.
I do it that way for what I consider good reason, but maybe someone needs to teach me the BEST way to build levels. Is it "tilebased"? I've read about it and heard that's one of the great things about doing it that way...but I haven't given in to it yet. Maybe it's time. Does anyone have a better way than that to point me at?
Bombdogs
03-12-2008, 11:44 AM
Interesting choice of methodology - tbh there is no right or wrong, just working properly or not working properly, if it works then hey, it's right.
Tile based is probably what you really want, it's very effiecient, there are level editors already out there that help you build tile-based maps - i think a popular one is called mappy. There are also a lot of really good tutorials to help you out with the tile-based basics - just hit google.
PMF
Don't code from inside MC. This way will make you run into so many scope problems that you have a good chance to never finish your game. Also, don't put element that you want to control (like your rock) inside other element that you want to control (like the walls). In a game each element should be on its own, with its own depth, with its own properties, so you can control it without running into problems. Each element must be free from other element so you can do whatever you want with them.
garlandpool
03-12-2008, 09:55 PM
Well, I really appreciate the good tips. I'll probably just break down and start obsessing over the tile-based method. I want to invest my time in a way that really pays and takes me the farthest. I'm tired of hitting walls.
I will also take ASWC's word for it and avoid the nesting symbols thing.
So, thanks VERY much for your input!
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.