00:00
00:00
Newgrounds Background Image Theme

KeyDraws just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

A wall. 2009-09-01 12:30:45


Hello, well this is most noob question in whole world, but i've been checking those goddamn tutorials and just couldn't find any help in making walls. Just stupid walls. For example i scripted bouncing ball from tut, but there was no floor, so it fell down the screen. I just don't get the idea how to make it. If anyone could be so nice and put here how to make it in AS 2.0 and 3.0, i'd be greatfull.

Response to A wall. 2009-09-01 13:25:33


Many ways to do a wall:

Using math, figure out a line, and then test the point on object A closest to the line to see which side it's on. If it's piercing the line, impulse penalty so it's no longer piercing the wall, then do the math to figure out a result vector from collision.

A shape that you hitTest against, and if the hitTest is true (can be shapeFlag, or entire object, depending), perform a collision reaction.

Hard-code maximum coordinates, and set a way to check to see if you're within these bounds, and if you are, resolve collision.

Basically, the idea is thus:
1. Figure out when I'm going to collide with a wall
2. Figure out how I collided
3. Figure out how to resolve that collision

So, go ahead, you know things like position, velocity, acceleration, and depending on how you set it up, you know where the 'wall' is. Apply some knowledge.


"Give a man a match, and he'll be warm for a minute, but set him on fire, and he'll be warm for the rest of his life."

Response to A wall. 2009-09-01 13:46:56


That didn't help. Didn't help at all. I see that there's an explanation, but i cannot operate with maths and all those things. Meaby some easy code for a wall so i could analyze it and learn something from it?

Response to A wall. 2009-09-01 14:13:30


Simplest wall for your falling ball:

You probably have an event that runs every frame, or some code that repeats at the frame rate. This code changes the x and y position of an object, right?

So you have velocity and position.

Now, since this routine runs every time the ball moves, you can check to see where it was, and where it'll move to, correct?

So, you have the final position of the moving routine.

Now, let's pretend the "ground" is a line across the bottom of the screen. In Flash, the top has a y value of 0, the bottom has a y value equal to the stage height. So, let's say the "ground" is 25 pixels above the bottom of the screen. If you're using the default stage size, that'd be 550-25, which is 525. Now we have a maximum possibly y value.

So, you have where the ball came from, where it ended, and the furthest it can go before doing something different than falling. Here's an example of how that can be applied (pseudo code):

First, initalize some variables once.

y velocity = 0
gravity = 0.5
bounce factor = 0.9
ground = 525

Next, we have the routine that'll run at the frame rate.

y += y velocity
y velocity += gravity <--that's where you stop if it just falls. Now let's test the ground.
if (y >= ground){ <--simple if statement. Will run the logic inside the {} if the condition is true
y = ground <-- the ball may sometimes pass beyond the ground if the increment is too large. This will remove that error
y velocity = -y velocity * bounce factor <--simple bounce logic. The velocity will change direction after the collision, but at a smaller value. That's where the bounce comes in.
}

And that'll make a 'wall' at y = 525.
You can replace the hard-coded number with any method of detecting a collision.


"Give a man a match, and he'll be warm for a minute, but set him on fire, and he'll be warm for the rest of his life."

Response to A wall. 2009-09-01 14:35:29


well, i didn't mean the wall to that bouncing ball. That was just an example. I wanted just wall. Like in platformers or any other shit with blocks that you cannot go thru. They just stop you. And i mean that block. Just a simple wall, or object that our hero cannot go thru. I thought it's obvious when i started the topic. I'm not pissed r something, but that's just not that what i want :/. So, any codes/ "tutorials" for that?

Response to A wall. 2009-09-01 15:10:02


I know what you wanted. I gave you an answer of exact methods on doing this. Essentially, I'm saying:

Write your own god damn code

Look up things like hitTest (I mentioned above), and other things. You can even do it math based if you were so inclined. But yes, lok up things like hitTest, instance names, and shape flags in the documentation, and you'll find what you're after.


"Give a man a match, and he'll be warm for a minute, but set him on fire, and he'll be warm for the rest of his life."

Response to A wall. 2009-09-01 15:36:03


Ok, now i think i get it. Thanks

Response to A wall. 2009-09-01 16:33:37



BBS Signature

Response to A wall. 2009-09-03 12:13:50


At 9/1/09 04:33 PM, smileinyoursleep wrote: if you need help theres tutorials here on new grounds with ground checks
http://www.newgrounds.com/portal/view/46 5099

Yeah, i tried that one. My character fell down and stopped falling then being in half under the "ground". Then i copied the script in case if i missed something, but it didn't seem to help. But i understand the basics, and even can make a wall, but now i have to learn about makingsuccesfull collision detect.