YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Post by Puzzlem00n »

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 145 times
I LÖVE, therefore I am.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Post by Kadoba »

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
I'm betting that is your problem. The player always gets pushed out of blocks by 1 unit even if the player overlaps between 0 and 1 unit so you have a "pop-out" effect. If the player is overlapping more than 1 unit then the condition above fails and it gets stuck.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Post by Puzzlem00n »

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.
I LÖVE, therefore I am.
User avatar
Whyte Vuh'uni
Prole
Posts: 7
Joined: Sun May 06, 2012 1:52 pm

Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Post by Whyte Vuh'uni »

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.

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
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)
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: YOU CANNOT FATHOM THE DEPTH OF MY FRUSTRATION.

Post by Puzzlem00n »

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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 10 guests