Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411658 Posts in 69395 Topics- by 58451 Members - Latest Member: Monkey Nuts

May 15, 2024, 10:29:56 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Coding 'Drop Floors'
Pages: [1]
Print
Author Topic: Coding 'Drop Floors'  (Read 1859 times)
Hangedman
Level 10
*****


Two milkmen go comedy


View Profile WWW
« on: June 11, 2010, 03:17:35 PM »

Cross-pollinated from the FP forums, because I realized I could throw this open to anyone, really. This isn't so much a Flashpunk question as a general programming question.

I'm making a fancy platformer, and attempting to code in two different floors: solid floors, and drop floors (floors that you can drop through by pressing 'down', that are only solid when you are on top of them.)

But no matter how I try to program it, I always get errors where my character is clipping through the floors and getting stuck, or just falling through. I've played with the player hitboxes, the floor hitboxes, the physics/clipping code...

Can someone elaborate the most practical method for doing this?
I can do the code, I just can't figure out a good method.
Logged

AUST
ITIAMOSIWE (Play it on NG!) - Vision
There but for the grace of unfathomably complex math go I
Skofo
Level 10
*****



View Profile
« Reply #1 on: June 11, 2010, 03:44:47 PM »

This is how I'd do it:

When you press down, set a variable that corresponds to the y coordinate right under your character. In the collision code between the character and floor, make it check if the floor intersects with that y coordinate--if it does, then quit the function before the actual collision code. Reset the variable once the character stands on another floor.

You might need to turn that y coordinate into a range of y coordinates if you have slopes or something.
« Last Edit: June 11, 2010, 03:50:09 PM by Skofo » Logged

If you wish to make a video game from scratch, you must first invent the universe.
Rob Lach
Level 10
*****



View Profile WWW
« Reply #2 on: June 11, 2010, 04:14:56 PM »

If you are constantly in the colliding state (ie when you're standing on something), set the player's y-coord relative to what the player is colliding with from below and keep it like that until you explicitly leave that stae (by running off the side (x-coord check) or jumping or getting attacked, whatever). That way if it moves up/down you'll player will just be glued to it. You can do something similar for x if you want platforms that move sideways.
Logged

Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #3 on: June 12, 2010, 04:31:54 AM »

I assume there's some kind of flag for setting collisions? If there is, then how about, when the down key is pressed, setting that flag to false (no collision) until the characters y is more than the height of the character below It?
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #4 on: June 13, 2010, 02:52:32 PM »

Here's how I do this:

First, I have two distinct types of solids: SOLID and JUMPTHRU. SOLID is completely solid, the player will never be inside it. JUMPTHRU the player can enter from below or beside but not above. So if the player is fully above a JUMPTHRU and moving downward and hits it, he stops. If the player is even one pixel within a JUMPTHRU he will not collide with it moving downward, and he never collides with it in any other direction.

Then, if the player is standing on a JUMPTHRU holding the down key and he presses jump, just drop him down one pixel and the collision system will take care of him falling.
Logged

Hangedman
Level 10
*****


Two milkmen go comedy


View Profile WWW
« Reply #5 on: June 13, 2010, 03:40:12 PM »

Here's how I do this:

First, I have two distinct types of solids: SOLID and JUMPTHRU. SOLID is completely solid, the player will never be inside it. JUMPTHRU the player can enter from below or beside but not above. So if the player is fully above a JUMPTHRU and moving downward and hits it, he stops. If the player is even one pixel within a JUMPTHRU he will not collide with it moving downward, and he never collides with it in any other direction.

Then, if the player is standing on a JUMPTHRU holding the down key and he presses jump, just drop him down one pixel and the collision system will take care of him falling.

This was essentially what I attempted to do, except I ran into issues with detecting collision with a full-sized hitbox. Essentially, my character gets stuck in the floor because without multiple hitboxes...

Crap. I just figured out how to do it!
Only collide in the usual way (x, y+1), but not when he's intersecting it in any other way.
I know that seems like common sense, but I've been looking for too many complex solutions to have thought straight until now.

Thanks for the advice everyone!
Logged

AUST
ITIAMOSIWE (Play it on NG!) - Vision
There but for the grace of unfathomably complex math go I
deemen
Level 0
***


View Profile WWW
« Reply #6 on: June 13, 2010, 03:50:32 PM »

I've found the best way to handle this kind of platform is with a state machine setup. You want to be able to prevent "tunnelling" in your physics, and this helps with that.

Basically you create two states "above" and "below". If the player is above, then he collides with the platform. If he's below, he doesn't. You use the line segment representing the top of the platform to handle the state changes.

Code:
1   |    2    |   3
    |         |    
----===========----
    |         |      
4   |    5    |   6

(Equal sign is the platform. Other lines show different areas)

Basically you make a state machine where 1, 2, 3 are "above" and 4, 5, 6 are "below". Then you allow state changes both ways for 1 <=> 4 and 3 <=> 6 but only one way for 2 and 5, 5 => 2.

Then, to handle the Drop Floor problem, all you do is swap the state to "below" and the character will stop colliding with the platform.

Hope that helps, even if you already found your solution Smiley.
Logged

Project Lead - Programmer @ Crankshaft Games
Current Project: Party of Sin
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #7 on: June 13, 2010, 04:13:17 PM »

Here's how I do this:

First, I have two distinct types of solids: SOLID and JUMPTHRU. SOLID is completely solid, the player will never be inside it. JUMPTHRU the player can enter from below or beside but not above. So if the player is fully above a JUMPTHRU and moving downward and hits it, he stops. If the player is even one pixel within a JUMPTHRU he will not collide with it moving downward, and he never collides with it in any other direction.

Then, if the player is standing on a JUMPTHRU holding the down key and he presses jump, just drop him down one pixel and the collision system will take care of him falling.

This was essentially what I attempted to do, except I ran into issues with detecting collision with a full-sized hitbox. Essentially, my character gets stuck in the floor because without multiple hitboxes...

Crap. I just figured out how to do it!
Only collide in the usual way (x, y+1), but not when he's intersecting it in any other way.
I know that seems like common sense, but I've been looking for too many complex solutions to have thought straight until now.

Thanks for the advice everyone!

 Beer! Now try to make your platforms move Tongue
Logged

Hangedman
Level 10
*****


Two milkmen go comedy


View Profile WWW
« Reply #8 on: June 13, 2010, 04:53:26 PM »

Beer! Now try to make your platforms move Tongue

 Crazy
Logged

AUST
ITIAMOSIWE (Play it on NG!) - Vision
There but for the grace of unfathomably complex math go I
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic