YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
I have been messing with this code all day long and I still can't figure out what I'm doing wrong. Basically, I'm trying to make an art-based platforming engine. With rooms and such. I'm using some collision code based off YellowAfterLife's Platformer Engine, which may have been a mistake since I'm not working with tiles, but I'm too deep in now. Basically, the player.y should be stopping right at 360 and staying there, but it doesn't, it floats above it for awhile and then randomly chooses a time to sink down where it should be. And then, worse, if you leave it sitting still, it randomly chooses a time to sink down again to 361, and then you're stuck in the ground. Basically, something's happening to make it want to go down and not go down at unprecedented times. I think it may partly have something to do with the value of the dt, but I can't tell. Anyway, the .love file is attached, and it's made to print the player.y value into the console. You guys are likely my only hope for ever fixing this.
- Attachments
-
- Lifezone.love
- May the force be with you.
- (11.34 KiB) Downloaded 144 times
I LÖVE, therefore I am.
Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
Code: Select all
if mapCollide(player.x, player.y + player.h) and not mapCollide(player.x, player.y + player.h - 1) then
player.y = player.y - 1
end
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
You would think so, right? But when I comment it all the problems persist. Like I said, I've been banging myself over the head with this forever. It's strange, the same collision code works flawlessly with bigger tiles, leading me to think the problem lies with something involving size differences.
EDIT: Ah, I have realized that that does fix something though. Before, if you were to stand at the correct 360 height and then walk, it would go back to floating. Now, walking at 360 will keep you at 360, although it is still possible to float after jumping and coming back to ground, as well as sink.
EDIT: Ah, I have realized that that does fix something though. Before, if you were to stand at the correct 360 height and then walk, it would go back to floating. Now, walking at 360 will keep you at 360, although it is still possible to float after jumping and coming back to ground, as well as sink.
I LÖVE, therefore I am.
- Whyte Vuh'uni
- Prole
- Posts: 7
- Joined: Sun May 06, 2012 1:52 pm
Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
Your problem is the use of math.floor instead of math.ceil... remember, the y axis is inverted, so the "bottom" is the mathematical ceiling.
You'll need to do something similar with left/right movement... I didn't bother testing those. Horizontal movement is overrated anyway.
Edit: oh, just in case it helps... your original code would cause you to sink only when k*j == 1 (i.e., low framerate; try starting multiple instances of your app to test that, or induce some artificial lag, or just set k to always be either 1 or 0)
Code: Select all
if mapCollide(player.x + 1, player.y + player.h + k*j) or mapCollide(player.x + player.w - 1, player.y + player.h + k*j) then
player.y = math.ceil(player.y)
player.ySpeed = 0
elseif mapCollide(player.x + 1, player.y + k*j) or mapCollide(player.x + player.w - 1, player.y + k*j) then
player.y = math.ceil(player.y) -- this one might be wrong... I can't bump my head into anything to test it
player.ySpeed = 0
else
player.y = player.y + k*j
end
Edit: oh, just in case it helps... your original code would cause you to sink only when k*j == 1 (i.e., low framerate; try starting multiple instances of your app to test that, or induce some artificial lag, or just set k to always be either 1 or 0)
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.
I have no idea how you figured that out, but who cares? It's fixed! Thank you so much!
I LÖVE, therefore I am.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests