[library] bump 2.0 – Collision Detection

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by Jasoco »

Yeah. I was doing it that way. But I'm having some interesting problems. I assume they're just me doing it completely wrong. Here's a video to show what is happening...


Red, green, blue and brown are different collision block types. The only one that is passthrough is the green. All the rest are solid.

And my current code for this. Basically straight jumping through the bottom of a passthrough (Solid on top only) platform will work fine. No problem at all... But any other collisions will negate any successful passthrough and push the player collision box out. Not sure exactly how to code it correctly. Also I can't pass through the left or right sides of the top solid boxes which I want to be able to do. Basically I just want to be able to pass through the left, right or bottom sides but only collide with the top.

Code: Select all

local playerFilter = function(other)
	local p = game.player
	local okind = other.kind
	return (okind == "wall" or okind == "block" or okind == "destroyableWall" or not okind == "bomb") and not (other.solidTop and p.y + p.h > other.y and p.x + p.w > other.x and p.x < other.x + other.w)
end

function player:moveColliding(dt)
	self.onGround = false
	local world = self.world

	local future_x = self.x + self.vx * dt
	local future_y = self.y + self.vy * dt

	local cols, len = world:check(self, future_x, future_y, playerFilter)
	if len == 0 then
		self:move(future_x, future_y)
	else
		local col, tl, tt, nx, ny, sl, st
		local visited = {}
		while len > 0 do
			col = cols[1]

			tl,tt,nx,ny,sl,st = col:getSlide()

			self:changeVelocityByCollisionNormal(nx, ny)
			self:checkIfOnGround(ny)

			self:move(tl,tt)

			if visited[col.other] then return end -- prevent infinite loops
			visited[col.other] = true

			local tl, tt, nx, ny = col:getTouch()

			cols, len = world:check(self, sl, st)
			if len == 0 then
				self:move(sl, st)
			end
	    end
	end
end
You'll notice the code is pretty much the same thing from the demo with slight changes. I didn't want to break what already works. Also, yes, I use X and Y instead of L and T. It just seems more correct to me.

I know you're releasing a new version soon but unless it's tomorrow I'd really like working code as soon as possible. I'll rewrite it when the time comes but for now I really want it to work.

Thanks for any help you can give.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by undef »

kikito wrote: Bump works in a "continuous" way - it does not only check if things are "currently inside others" - it also checks that "things have gone through others" (even if they are not currently colliding at this very instant). Figuring out how to do that was what took me the most time.
Wow, that sounds like a fun thing to figure out! :)
Thanks for the explanation anyway.
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by kikito »

Hi jasoco,

Thanks for putting the video up.

I don't see anything immediately wrong with your code. It might be that there is a bug in bump.

This comes at a really bad time I am afraid. Today & tomorrow I will be travelling and it's going to be difficult for me to work on this at all.

However, in case I can, could you please upload your complete .love, so I can do real tests instead of "imagining" what might be happening?
When I write def I mean function.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by Jasoco »

Okay. I had to throw it together since I was actually working on it inside a state in my RPG project. But now it's self-contained so you can play around.

Anyone else who wants to toy with it can too.
Platformer.love
(19.72 KiB) Downloaded 185 times
Thanks for anything you might notice.

Also, yes, I did write an algorithm to optimize the number of collision boxes created on a grid-based map system. It's my crowning achievement, but if you have any ideas how to make it more optimal let me know. (Just look at the boxSizeList table.)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by s-ol »

kikito wrote:Hi.
-snip-
Enjoy!
WOW! I've been in this thread multiple times now (to make the red "new" thingy disappear) but I never bothered looking at the library too well, and...
I'm impressed! The API is much more useful than HardonColliders, I was almost not going to look at it bc of AABBs, but I am sooo relieved I did; implementing platforming with HC was a task almost too complicated for me already (in a near-perfect matter with no glitching into or out of walls).

Especially the (tiny) resolving methods are soo useful, good job! :o

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: [library] bump 2.0 – Collision Detection

Post by Doctory »

hi, im looking and the simple demo and i have 1 question
is l and t equal to x and y?
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by Jasoco »

Doctory wrote:hi, im looking and the simple demo and i have 1 question
is l and t equal to x and y?
Yeah. L is Left and T is Top. Which is basically X and Y. Not sure why kikito uses L and T but it shouldn't matter since you can still use X and Y externally in your objects. L and T are really only used internally in the library from what I can tell. You could change most of the L and T variables to X and Y and it would probably still work fine.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by kikito »

Hi there,

Yesterday I did the thing I had been preparing for the last 2 weeks or so (I did a presentation for a programming group) and I can now get back to programming.

@Jasoco, I will give a look at your code this evening (it is morning for me, I gotta work and stuff first)

@S0lll0s, I am glad you liked the lib :) On the next version, some methods will be renamed/improved and will return different kinds of things (i.e. tables instead of multiple numbers), but I will keep it minimal & small. I think it will be easier to use.

@Doctory, I confirm that I use l & t for "x" and "y" - they mean "left" and "top" respectively. But you are not the first person who gets confused by this. It is one of the things I have changed on the next version: I use "x" and "y" there already.
When I write def I mean function.
Apito
Prole
Posts: 2
Joined: Sat Nov 22, 2014 5:44 am

Re: [library] bump 2.0 – Collision Detection

Post by Apito »

Hi kikito,

Thanks heaps for this library, it's really helpful! I am having a small issue and was wondering what you make of it. Basically, if I have floor tiles that are the same width as the player, sometimes the player gets stuck. This happens mostly in corners. I've modified the bump-demo code to reproduce the problem, the changes I've made are:

- Commented out code for generating middle blocks and guardians
- Remove flying
- Resize world
- Change tiled floor blocks to the same size as the player

If you start up the game and move into the left wall while on the ground, roughly half the time you can't move right. Let me know if you can't reproduce it and I'll make a video.

Thanks.

Edit:
I adjusted the starting position of the player so they sometimes can't move left or right after falling to the floor when spawning.
Attachments
bump-issue.love
(123.12 KiB) Downloaded 332 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump 2.0 – Collision Detection

Post by kikito »

@Jasoco:

I have some good news! I found and fixed a couple issues in your code, and now all the weird resoultion issues are gone:

Mi changes:
  • The most glaring problem was that you forgot to include the playerFilter on second "world:check" at the end of the while loop. That's what made platforms "sometimes solid" when they should be pass-through; they were only pass-through when they were the first collision that occurred, never the second.
  • I think there was also a problem with the way future_x and future_y where handled. They retained their initial values all the time - so the player "tried to get to them" even after making a sliding collision with a platform. I have changed that so that when the player slides over anything that updates the value of future_x and future_y. I am not sure if that fixes anything, but it makes more sense physically speaking. I will check my demos to make sure that I do so in them as well.
I might have changed some other thing here and there, but those are the most important changes I think. Attaching the fixed Platformer.

@Apito:

I was able to reproduce the bug with your code. Thanks a lot for taking the time to write it, by the way! Another person reported a similar issue but I was not able to reproduce it.

I have not been able to investigate it yet, and I don't have any idea of how much time will it take me to find and solve the issue. It could be one stupid < instead of a <= somewhere, or something more serious.

I will try to fix this on the next version of bump - it presents collision information in an easier way, which might also help.

In the meantime, please try making the player slightly slimmer than the blocks, and see if that helps.
Attachments
Platformer-fix.love
(21.38 KiB) Downloaded 137 times
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests