Inter-entity Collision in Goature's System

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
thebassinator143
Prole
Posts: 4
Joined: Sat Mar 01, 2014 10:06 pm

Inter-entity Collision in Goature's System

Post by thebassinator143 »

Hello Love community! I have been working with Love (and lurking these forums) for a month or so, and must say I've been enjoying it immensely :D

Greetings aside, I seem to have run into a bit of an obstacle :( I'm working on a platformer (using Goature's entity system) and am currently stumped in trying to figure out how to make the damn entities collide with each other! Currently, all entities are able to collide with the player (who was not made with the entity system) using simple bounding boxes, but cannot collide with one another because I do not know how to get the updated x and y positions from each individual entity.

Goature's system essentially makes a copy of all the information from the entity files (in this case, hellhound.lua & spike.lua) and places them into the table ents.objects with their unique x and y positions (as defined in ents.Create("name", x, y, BG)) each time you create an entity. The question is how I can access the updated x and y positions of each individual entity so I can check for collisions?

Ideally, I would like to edit the ents.Create function so that each time you create an entity, it stores the unique positional information of the entity in such a way that you don't have to manually add it to the collision check table. Honestly, I'm not sure how to do this, or if I'm even thinking along the right lines. Would anyone have an idea as to how I can go about addressing this issue?

Thanks in advance to anyone who takes the time to read/respond... much appreciated!! :D

P.S. It uses AdvTiledLoader so you'll need love 0.8.0 to run the .love.
https://bitbucket.org/rude/love/downloads I berieve you can get it herrrr if you don't have it.
Attachments
Project Brutality.love
(80.6 KiB) Downloaded 122 times
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Inter-entity Collision in Goature's System

Post by Ranguna259 »

How are you making the entities bounding boxs of the objects when they are colliding with the player ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
thebassinator143
Prole
Posts: 4
Joined: Sat Mar 01, 2014 10:06 pm

Re: Inter-entity Collision in Goature's System

Post by thebassinator143 »

Ranguna259 wrote:How are you making the entities bounding boxs of the objects when they are colliding with the player ?
So the player data is all located in the player.lua file, completely independent of the entity system. Since there is only one player, this allows me to call that data (x,y,w,h) in the entity files, which in this case are hellhound.lua and spike.lua. Here is the relevant code located in the ent:update(dt) function of hellhound.lua:

Code: Select all

if ents:CollidingWithEntity(self.x - (self.w/2), self.y - (self.h/2), self.w, self.h, player.x - (player.w/2), player.y - (player.h/2), player.w, player.h) then
		player:damage(self.damage)
		print ("Hellhound colliding with player!")
	end
So now every hellhound will check its unique data against the player's, allowing player-entity collisions to happen. But what about entity-entity collisions? Somehow there needs to be a distinction between the different types of entities so I can resolve the collisions differently (ie an entity colliding with an axe thrown by another entity vs. simply bumping into one another).
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Inter-entity Collision in Goature's System

Post by davisdude »

You could make an "enemy.type" variable, or something along those lines, use an if-statement to check the type, etc.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Inter-entity Collision in Goature's System

Post by Ranguna259 »

so for each entitie you have a x and a y variable like:

Code: Select all

entitie.x = --x coord
entitie.y = --y coord
Right ?
Also, how are you drawing the entities ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
thebassinator143
Prole
Posts: 4
Joined: Sat Mar 01, 2014 10:06 pm

Re: Inter-entity Collision in Goature's System

Post by thebassinator143 »

@davisdude: I think that's a great idea, thanks! :D Before that can happen though, I need to get the updated entity coordinates so I can check for the collisions

@Ranguna: That is essentially correct. The entity files (hellhound.lua and spike.lua) are basically templates for creating different types of entities, so that every time you call the ent.Create function, you create a unique copy of the given entity (hellhound, for example) with its own unique x and y coordinates. Each unique hellhound is essentially a table of ALL the information from hellhound.lua; the only thing that makes hellhound 1 different from hellhound 2 is its unique x and y coordinates. Otherwise, they are more or less carbon copies of one another.

So, conceivably, each hellhound has its own x and y coordinates. The problem I suppose is that they are all copied from the exact same file, which defines their variables as being self.x, or self.y, and so on so forth for all other relevant data. Within the file, the self can be translated to ent. The problem is that every single entity uses the prefix (sorry for my terminology, I'm a noob) ent... so how can I call ent.x in another file when every single entity essentially uses ent.x?

It may be easiest for you to just take a look at the files (entities.lua, hellhound.lua primarily) to see how they are working. All these nested tables and localized variables make my head hurt :P

As far as drawing entities, that's pretty simple: in entities.lua, there is an ents:Draw() function. This function calls a function called ent:Draw() which exists in each entity's file, and iterates through ents.objects (which is the table containing every entity used in the create function). Then, the ents:Draw() function is simply called in love.draw, and voila!

Apologies for the length of my responses!
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Inter-entity Collision in Goature's System

Post by Puzzlem00n »

(I sent this to him in a DM conversation, which I might as well copy/paste here for posterity.)

Hm. This system Goature wrote is weirder than I remember. Oh, wait, ent.create gives them ent.types automatically! Wonderful.

Okay, the way to do this doesn't seem very good or efficient, but on the most basic level, you're going to have every single entity loop through every other entity to see if they collide.

Basically, what I'm saying is, in entities.lua:

(EDIT: Code was rushed and badly written, hopefully I just fixed it.)

Code: Select all

function base:update(dt)
   for i, ent1 in pairs(ents.objects)
      for i, ent2 in pairs(ents.objects)
         if ent1.x < ent2.x+ent2.w and ent1.x+ent1.w > ent2.x and ent1.y < ent2.y+ent2.h and ent1.y+ent1.h > ent2.y then
            if ent1.type == "hellhound" and ent2.type == "spike" then ??? end
            if ent1.type == "spike" and ent2.type == "spike" then ??? end
            if ent1.type == "hellhound" and ent2.type == "hellhound" then ??? end
         end
      end
   end
end
There could be some errors in there, I wrote it quick, didn't test.

This might seem horribly inefficient to you, and that's because it is. The majority of the time, you're going to be checking whether an entity collides with something all the way on the other side of the screen. Ideally, you'd make sure to not bother with those checks. But if you want to do it yourself, this is the first step. If not, I'd recommend checking out bump.lua, which is far more efficient.
I LÖVE, therefore I am.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Inter-entity Collision in Goature's System

Post by Ranguna259 »

Perfect, now that I had enought information to answer the thread, you did Puzzlem00n :rofl: , the first time I got ninja'd here, I'll get my revenge, you'll see.. in time.. ( ;) )
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Inter-entity Collision in Goature's System

Post by Puzzlem00n »

I'll make sure to look behind my back every once in a while.
I LÖVE, therefore I am.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests