Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[isometric] - Collision detection not working properly #52

Closed
eschnou opened this issue Apr 21, 2012 · 26 comments
Closed

[isometric] - Collision detection not working properly #52

eschnou opened this issue Apr 21, 2012 · 26 comments
Milestone

Comments

@eschnou
Copy link

eschnou commented Apr 21, 2012

The issue is related to #51 and the fact that in an isometric world, the tile 0 is in fact not at position (0,0) on the screen. This means that when the getTile(x,y) position is invoked for collision detection, the wrong tile is returned.

I guess this could be fixed by either managing the isometric case in a different way in the getTile function, or by computing xLUT and yLUT in a different way when in an isometric level.

@andyveliz
Copy link

I've wrote some code to fix #51, it's on issue #96, i hope this issue will be resolved as well... If it's not fixed... i'll code a little more... i need Collision detection too...

@andyveliz
Copy link

Well i've been working around this problem, and as i've realized that in an Isometric map, the collitions are made when the base of two objects are colliding, not the rectangles around them.
ejemplo_colision_iso

So, i've been able to even correctly zSort objects, but using extra parameters:

  • width of the base (in tiles)
  • height of the base (in tiles)
  • x position of the first tile (in pixels)
  • y position of the first tile (in pixels)

ejemplo_parametros_iso

these parameters also fix the positioning bug, because we can translate the tile to pixels position, and get the pixel position of the tile where the object must be placed, and then substracting the position on the first tile, we can place the object correctly.

ejemplo_posicion_iso

I know there's probably a better way of doing it, but this is how i've done it, also I have a little method for zSorting the isometric objects, there's also a little patch for melonjs.

Maybe we can get some of this bugs fixed...

I hope this helps

@parasyte
Copy link
Collaborator

For this one, we just need non-AABB collision detection. #103 includes some improvements to the general collision detection system. Apart from the performance boost, it also changes the internal storage structure used to determine how objects should be considered for collision tests (this is before the actual collision tests take place).

With the new storage system, we can now support "collision object layers" in a map, so any polygon or polyline object can be used as collision shapes.

That said, the focus on #103 is on the performance aspect and fixing general bugs. Another ticket should be created for adding non-AABB collision tests. I know there was discussion on some other tickets about implementing the Separating Axis Theorem algorithm, though there are others available as well, like Minkowski Difference Also, I found https://github.com/jriecken/sat-js which we may be able to use directly.

Anyway, with a better collision testing algorithm, those collision shapes can easily be created using the polygon object tool in Tiled. This is the only thing that I can recommend, moving forward. Attempting to wrangle the AABB tests to support per-pixel collisions on isometric rectangles is not going to be pretty. And we already have to do something similar for backward compatibility with slope tiles. :(

@mik01aj
Copy link

mik01aj commented Nov 26, 2013

Well, instead of "attempting to wrangle the AABB tests to support per-pixel collisions on isometric rectangles", you could calculate collisions in tile coordinate system - this way the bases would be perfect rectangles.

@mik01aj
Copy link

mik01aj commented Nov 27, 2013

Yes, I thought more about it, and basically the same approach would work for both types of maps (orthogonal and isometric). The only drawback I see is that you'll have to call renderer.pixelToTileCoords and renderer.tileToPixelCoords sometimes. But it shouldn't be hard to do.

@obiot obiot added this to the 1.2.0 milestone Jul 28, 2014
@obiot
Copy link
Member

obiot commented Jul 28, 2014

i did not really tested that one, but with the new SAT based collision algorithm, and the coming ticket #538 , this one should be done too.

(keeping it open until properly tested)

obiot added a commit that referenced this issue Oct 10, 2014
…e collision system

based on the following one, courtesy of Pierre, that I had hanging
around since a while :
https://github.com/mfpierre/melonJS/tree/isometric_example
@obiot
Copy link
Member

obiot commented Oct 10, 2014

here is the result so far :
image

@parasyte
Copy link
Collaborator

Hehehe! I see the projection on the shapes needs to be fixed. So this should be really done after that!

@agmcleod
Copy link
Collaborator

That looks cool though :)

On Fri, Oct 10, 2014 at 3:43 AM, Jay Oster notifications@github.com wrote:

Hehehe! I see the projection on the shapes needs to be fixed. So this
should be really done after that!


Reply to this email directly or view it on GitHub
#52 (comment).

Aaron McLeod
http://agmprojects.com

@obiot
Copy link
Member

obiot commented Oct 14, 2014

so I've been playing with this one a bit, rotating shapes by 45", scaling vertically by 0.5 and translating by half the height, and yet it is not coming out right at all, so it appears this is a bit more tricky that I initially thought :)

@agmcleod
Copy link
Collaborator

nah cause i think the scaling would compound. I think that would work if it wasn't for the rotation.

@obiot
Copy link
Member

obiot commented Oct 14, 2014

what do you mean by "would compound" ?

@agmcleod
Copy link
Collaborator

Probably a bad choice of words (had no caffeine at the time, and it's morning). Meaning when you perform a rotation, then scale & move up, spaces would likely appear in spots that you don't expect them to. Doesnt know how to consume the space between tiles as easily.

@parasyte
Copy link
Collaborator

As far as I know, the only requirement is rotate and scale. Both operations need to be anchored on the same point.

@parasyte
Copy link
Collaborator

screen shot 2014-10-14 at 11 55 47 am

All done.

@agmcleod
Copy link
Collaborator

amazing!

On Tue, Oct 14, 2014 at 2:56 PM, Jay Oster notifications@github.com wrote:

[image: screen shot 2014-10-14 at 11 55 47 am]
https://cloud.githubusercontent.com/assets/456942/4634810/d043d5f4-53d3-11e4-83d0-7a5f424c9144.png

All done.


Reply to this email directly or view it on GitHub
#52 (comment).

Aaron McLeod
http://agmprojects.com

parasyte added a commit that referenced this issue Oct 14, 2014
…jection

- Do not reuse vectors between each line segment in a TMX PolyLine, or rotation/scale will double the operation on each.
- Fixed some documentation in TMXObjectGroup.
- Added a new `orientation` property to TMXObject.
- Added collision detection and simple 8-way movement to the isometric RPG example.
- The numbers used to scale are arbitrary, and I came upon them through trial and error. I originally thought (4 / 3), (2 / 3) would work, but that make the shapes too small.

TODO:

- Come up with a better rationale for the magic numbers
@parasyte
Copy link
Collaborator

Looks good on my end. This can be closed, even though there's a TODO note in the commit comment. ;) It's not a super big deal, I just don't really understand what the numbers in scale(1.4132, 0.705) mean.

@agmcleod
Copy link
Collaborator

Out of curiousity, how well does it work when you walk around the tree or rock with just the one side for collision?

@parasyte
Copy link
Collaborator

About as well as you expect. ;)

I'm not sure why those were the only shapes placed for the rocks and tree. It would be better to just use rectangles for those.

@parasyte
Copy link
Collaborator

Spoke too soon! Rectangles are not positioned correctly. Even the player entity's default position doesn't match Tiled

screen shot 2014-10-14 at 12 23 01 pm

screen shot 2014-10-14 at 12 25 15 pm

@parasyte parasyte reopened this Oct 14, 2014
parasyte added a commit that referenced this issue Oct 14, 2014
- Circle positions are still incorrect, but will be fixed when rotation and scaling is supported for that shape.
@parasyte
Copy link
Collaborator

Woohoo! DONE and DONE! The only thing left is properly scaling and rotating the ellipses. That will be taken care of in #583

@obiot
Copy link
Member

obiot commented Oct 15, 2014

I cannot beleive this one is finally closed, and how almost easy it was with the new collision system!

That was a beautiful work team guys :):):)

@aaschmitz
Copy link
Contributor

Woooh, congrats @parasyte, @obiot and @agmcleod, melonJS 1.2 will be another great version! Thanks for the well done job!

@jumpjack
Copy link

How do I enable debug panel in melonJS 2?

@obiot
Copy link
Member

obiot commented Nov 27, 2022

@jumpjack
Copy link

and how do I enable devrlopment mode? I am not very expert, I don't know anything about wasm, em6, ecmascript, boilerplate or whatelse, I use plain javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants