The Physics of Cave Story

Mar 29, 2011 at 7:12 PM
Junior Member
"It's dangerous to go alone!"
Join Date: May 22, 2008
Location:
Posts: 35
Regrettably, I am a liar, and who would of thought that square tile collision could be so painful...

However, I finally took the code to court and won out, so now all collisions are back to normal, in fact, they are better than normal. I fixed the tile hit then jump problem. It is once again held together through a small for loop that places quote as close as possible to the block as soon as he goes to collide. It sucks, but the math I have been trying to do was so borked that quote would go flying half across the screen in some cases.

Also, scaling. I have the scaling set up correctly now. The screen size was always supposed to be for a 2x2 scale of the graphics, but I had troubles with camera offsets in such cases. Since Pixels code was set up differently I had to experiment with the variables myself to figure things out. If you want... you can set the Game.scale variable to anything you want and the graphics will set up accordingly... although the window size remains constant.

Directions! I added the six possible directions of face for any actor. This means quote can look up and down. And with looking down comes a new collision block I named ledges for lack of knowing the original name. You can look down to fall through them. Also, looking down while on the ground draws differently than looking down in the air!

I didn't put in a sticky block, but if anyone wants to try making a new block class they are welcome! (the Arkiv1 contains the full netbeans distribution)

TL;DR
• Refactored and upgraded collisions
• Arbitrary scale (static window size)
• Player directionality
• Ledge blocks (look down to fall through)

[EDIT]
Almost forgot, it turns out that quote in my simulation is traveling quite farther than he should. I nailed it down to their being no friction in the air... but if I do add friction it over comes the air control.... What value is their for air resistance?
 
Mar 29, 2011 at 7:19 PM
Lvl 1
Forum Moderator
"Life begins and ends with Nu."
Join Date: May 28, 2008
Location: PMMM MMO
Posts: 3713
Age: 32
A block class?

Having the blocks as objects is rather inefficient, don't you think? Making every block an object is rather memory intensive since there's so many of them. I recommend that you instead store the blocks as a 2-D array, and store their collision type there. (You could have 2 different arrays, one for type and one for the graphic it's supposed to render from the sheet. That's what cave story does I think).
 
Mar 29, 2011 at 7:29 PM
Junior Member
"It's dangerous to go alone!"
Join Date: May 22, 2008
Location:
Posts: 35
GIRakaCHEEZER said:
Having the blocks as objects is rather inefficient, don't you think?

I suppose I agree with you. It probably is going to become a nightmare for me farther along the line:muscledoc:... but I was trying to keep the code as organized as possible so that I would be motivated to keep working on it. It also makes it easy enough for coding greenies like me to make sense of my spaghetti. I will need to rethink my ideas later, but for now they make sense.
 
Mar 29, 2011 at 9:53 PM
Been here way too long...
"Life begins and ends with Nu."
Join Date: Jan 4, 2008
Location: Lingerie, but also, like, fancy curtains
Posts: 3052
you have a different accel speed and max speed while in air. you make sure you included those?
 
Mar 29, 2011 at 11:52 PM
Junior Member
"It's dangerous to go alone!"
Join Date: May 22, 2008
Location:
Posts: 35
If I knew what they were, I surely would include them! Are they in the code Noxid posted? If so I will check... or does the water constants apply to air in that case?
 
Mar 30, 2011 at 12:10 AM
Been here way too long...
"Life begins and ends with Nu."
Join Date: Jan 4, 2008
Location: Lingerie, but also, like, fancy curtains
Posts: 3052
p.walkspeed = 0x032c;
p.fallspeed = 0x5ff;

p.fallaccel = 0x50;
p.jumpfallaccel = 0x20;

p.walkaccel = 0x55;
p.jumpwalkaccel = 0x20;

p.decelspeed = 0x33;
p.jumpvelocity = 0x500;
p.jumpwalkaccel is the acceleration in air. Parently there is no different max speed, but that should change things enough.
 
Mar 30, 2011 at 12:28 AM
Junior Member
"It's dangerous to go alone!"
Join Date: May 22, 2008
Location:
Posts: 35
Oh! I didn't realize it, but I did in fact use an air acceleration constant.
My constants look like such:
Code:
final float FRICTION = ((float) 51 / (float) 512),
GRAVITY = ((float) 80 / (float) 512),
JUMPING_GRAVITY = ((float) 32 / (float) 512),
MAX_VX = ((float) 812 / (float) 512),
MAX_VY = ((float) 1535 / (float) 512),
WALK_ACCEL = ((float) 85 / (float) 512),
AIR_ACCEL = ((float) 32 / (float) 512),
JUMP_SPEED = ((float) 1280 / (float) 512);
and my application (for the left key press) is as such:
Code:
if (gc.getInput().isKeyDown(Input.KEY_LEFT)) {
if (quote.isOnGround()) {
quote.getVelocity().set(
Math.max(-MAX_VX, quote.getVelocity().getX() - WALK_ACCEL),
quote.getVelocity().getY());
} else {
quote.getVelocity().set(
Math.max(-MAX_VX, quote.getVelocity().getX() - AIR_ACCEL),
quote.getVelocity().getY());
}
}

But because AIR_ACCEL is less than friction, I had to drop adding friction altogether. Which means that quote simply flies whenever in the air and can make impossible 7+ tile unassisted jumps. I must be missing something because Liger's modding sheets state that the jumping distances should be smaller.
 
Mar 30, 2011 at 12:32 AM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
Pronouns: he/him
There is no friction in air normally, as far as I can recall, but did you perhaps forget to cap the maximum velocity?
 
Mar 30, 2011 at 12:39 AM
Junior Member
"It's dangerous to go alone!"
Join Date: May 22, 2008
Location:
Posts: 35
No, I'm sure I did. If I change the MAX_VX value, it is dreadfully obvious that quote moves slower when he jumps. I suppose I could experiment with several values....but that might give me something a bit off. I think I am going to download cave story on my older computer and test for air friction.

*edit*
And test I did. Lyger's sheets are completely accurate, so I really am somehow going much farther than should be possible.... off to test arbitrary values I suppose... *le sigh*

And my test results show that a value of around 650/512 is necessary to work. It allows the difficult booster save jump and prevents the impossible 7 tile jump, although the booster save jump feels easy... too easy. Oh well. The value in pixel's units should be a 0x28Au... I think I just might search the code Noxid sent for a hard coded value/magic number close to that.
 
Mar 30, 2011 at 2:07 AM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
Pronouns: he/him
I think it's kind of icky that you use float but w/e
The code I had is exactly how the player movement is controlled ingame, minus wind effects. That's all there is to it, basically.
 
Back
Top