1 decade ago
by stillen
To simplify the explanation, I'm dropping square entities in a tetris like game. I can detect collisions when they land on each other but not when they are next to each other.
I tried using the .touches() but it seems unreliable, working sometimes but not other times.
Is there something I can use to check if an entity is next to another and the axis? CollisesWith() doesn't work because they never really touch, and distanceTo() doesn't account for an axis.
Touches is intended to only record when two entities actually touch. In your case, set up a method similar to touches, which is only an AABB intersection test, with offsets. So you'd subtract some value from the top left and add the same value to the bottom right. The value could be whatever you feel is close enough to call two entities next to each other.
1 decade ago
by stillen
I figured I would have to write my own function to detect my being next to for my use, but I thought I might have missed something.
Where I am lost is how do pass the other entity to my function? I figure I could call my next to function within the entities update function to do the checking, but I don't know how to find/get the other entities available in my update, or how to find out which entities to check against without looping through all of them by type, and that just seems like alot of over head if we have a screen full of entities.
You could override the touches
method. Do the original check plus another check with the bounding box increased by whatever value makes one next to another. I could see issues with it not checking some entities, because touches
is only called on two entities that are in the same collision hash, and if your value that determines next is larger than the collision hash size you'll miss next checks. To fix this, you can make your own collision check for your tetris blocks with a hash that accounts for the value that determines next, and update it with the game loop in the same way the collisions are calculated.
1 decade ago
by stillen
I'm leaning to go away from the touches method, since all the items are on a grid, I can check the tiled location. I'm thinking it may be easier to check the grid location by overriding the distanceTo method and toss a check if the items match when the distance is one tile away.
-- edit --
After trying to do this with the distanceTo, I used that idea of the grid check on the touches method and everything seems to work as I wanted. Now I have to work on my game logic.
Page 1 of 1
« first
« previous
next ›
last »