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

Adding shapes to a Body dynamically does not project shapes in isometric maps. #601

Open
ldd opened this issue Nov 2, 2014 · 13 comments
Open
Labels

Comments

@ldd
Copy link
Contributor

ldd commented Nov 2, 2014

This applies for melonJS 1.2.0-beta

for reference, please look at
https://groups.google.com/forum/#!topic/melonjs/Tz8tUDHgDGw

I wanted to extend Entity objects without using Tilled.

This works perfectly, as done in the above forum post, but for 1.2 I needed to do
settings = {
//bunch of settings
orientation: "isometric",
getTMXShapes: new me.TMXObject('empty').getTMXShapes;
}
this._super(....,'init', [x,y,settings]);

With this small workaround, everything works perfectly and flawlessly.

put in other words:
either orientation or/and getTMXShapes are required in the settings when creating an Entity.

@parasyte parasyte added this to the 2.0.0 milestone Nov 2, 2014
@obiot
Copy link
Member

obiot commented Nov 3, 2014

Hi !

I'm a bit surprise as based on the following code getTMXShapes should be optional, and then orientation as well since only used when using Tiled :
https://github.com/melonjs/melonJS/blob/master/src/entity/entity.js#L191

are you using the last master branch version (it's not called 2.0.0 but we just basically renamed it to 2.0.0 to emphasize on all the underlying changes) ?

@ldd
Copy link
Contributor Author

ldd commented Nov 3, 2014

Oh sorry, allow me to clarify. calling init works, the entity displays on the map, etc but the moment it collides with something, unless getTMXShapes is there, I get an error.
ps: after some tests, I can confirm that orientation isn't required, so it all boils down to getTMXShapes being in the settings for collision to work

@parasyte
Copy link
Collaborator

parasyte commented Nov 3, 2014

There should never be any uncaught exceptions. @ldd Can you please give us the line number where the exception is raised? And also point out which build you are using. (Build number in the melonJS-builds bucket on S3, or a git commit ID)

This should be easy to fix, but an entity without a body shape is not supposed to collide with anything. Just keep that in mind.

@ldd
Copy link
Contributor Author

ldd commented Nov 3, 2014

Um.... there is no error actually.
I was getting an error back when I was using an incorrect approach to collisions after migrating to 1.2

Thus, the minor caveat is this:
using the hitbox on the debug menu, the object's shape is a rectangle that has not been rotated according to the isometric grid unless TMXShapes is present in the settings before calling _init.

Looking at the code, rotation happens in TMXShapes in the last step, when you do

shapes[i].rotate(Math.PI / 4).scale(1.4132, 0.705);

and body.getShape returns this.shapes[index]

In other words, I guess there is no bug. The programmer needs to make sure that shapes are properly setup => feel free to close this bug report

ps: I was using the tagged version 1.2.0-beta.1

@obiot
Copy link
Member

obiot commented Nov 4, 2014

hi ldd,

great then, thank you anyway for reporting here your findind about the beta, bug or not this is always positive feedback to improve the engine :)

@parasyte
Copy link
Collaborator

parasyte commented Nov 4, 2014

Just one comment, here. I think it is a bug, because it's not trivial to add shapes to an entity at runtime with an isometric map. We can make it better. Eg. it might be something like the me.Body.addShape method doing the isometric projects on the shape when added.

Anyway, this isn't a showstopper, so I think we can save it for 2.1.

@parasyte parasyte modified the milestones: 2.1.0, 2.0.0 Nov 4, 2014
@parasyte parasyte changed the title getTMXShapes and orientation are REQUIRED when initializing an Entity Adding shapes to a Body dynamically does not project shapes in isometric maps. Nov 4, 2014
@obiot
Copy link
Member

obiot commented Nov 4, 2014

indeed, when not using Tiled there is no proper way to indicate the orientation !

maybe not a bug though, but a missing feature probably :)

@agmcleod
Copy link
Collaborator

We should probably create a new issue dictating what needs to be done. I know we've looked at a bit of the shapes & tmx object data lately. What should be done in order to satisfy isometric shapes?

@parasyte
Copy link
Collaborator

I thought it was pretty clear by the description. But to describe further, when a shape is added to an isometric map (say a rectangle) it needs to be projected by rotation and scaling:

// Apply isometric projection
if (this.orientation === "isometric") {
for (i = 0; i < shapes.length; i++) {
shapes[i].rotate(Math.PI / 4).scale(Math.SQRT2, Math.SQRT1_2);
}
}

An ideal solution would be to do the projection only when drawing. (Leave the shape and positioning internally to simplify entity movement.) The initial work (linked above) was done as a stopgap to ensure isometric map support wasn't completely missing. This ideal solution should be tracked in a different ticket. But completing the stopgap would happen here.

@agmcleod
Copy link
Collaborator

An ideal solution would be to do the projection only when drawing. (Leave the shape and positioning internally to simplify entity movement.)

Makes sense. That way you're not dealing with "isometric units" directly. Though do physic shapes get saved as projected? Could be weird to have onething projected, and another note.

This ideal solution should be tracked in a different ticket. But completing the stopgap would happen
here.

alrighty

@parasyte
Copy link
Collaborator

In the ideal world, logical coordinates are always distinct from render coordinates; The axes do not necessarily point in any specific direction (relative to the screen) in a logical coordinate system. The shapes defined in the TMX are expressed in logical coordinates, which are roughly orthogonal. It's easiest to use these shapes directly for collision detection and entity movement. In other words, logical coordinates would be "native" to melonJS in that mode of operation.

That's the eventual goal, anyway, since it breaks the coupling between world physics and renderer; theoretically, a game can be rendered in 2D or 3D just by changing the drawing code, while everything else remains untouched.

@agmcleod
Copy link
Collaborator

Provided you put in 3d geometry ;)

@parasyte
Copy link
Collaborator

I mean that a simple renderer can just extrude shapes (pixels into voxels):

Voxel Mario

There are other examples to be sure, but that's what I mean by rendering a game in 2D or 3D by only changing the renderer. With an isometric game, you really need 3D coordinate space, anyway. The isometric renderer can be easily swapped out with orthographic or perspective renderers...

@obiot obiot modified the milestones: 5.0.0, 4.1.0 Jan 18, 2017
@obiot obiot removed this from the 5.0.0 milestone Aug 19, 2022
@obiot obiot added the Feature label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants