Rotate map AND physics

How would I go about rotating a map AND the physics? I can rotate the map just fine, using map.rotation = whatever, but doing physical.rotation = whatever doesn’t work. Help anyone? [import]uid: 8782 topic_id: 5028 reply_id: 305028[/import]

I’m not at my Pc right now but if map.world.rotation doesn’t work then you may have found a bug. [import]uid: 5833 topic_id: 5028 reply_id: 16452[/import]

Hmmm. It’s on hybrid mode, and the hybrid boxes move with the map, but the player doesn’t interact correctly. It still sits on a platform that existed before the map was rotated. I’ve inserted the player into a tilemap layer, but do I need to do something else? Here’s a link to the code: http://cl.ly/062y1u241H1z3m1y3D3z (check level1.lua, line 21 for the rotation stuff) [import]uid: 8782 topic_id: 5028 reply_id: 16459[/import]

I think you may have found a bug/limitation in Corona itself, as if you see my simple test here - http://dl.dropbox.com/u/571145/RotationTest.zip - rotation with physics all works fine when you rotate the image itself but if you rotate the group that the image and body are in it all goes haywire.

To demonstrate this just run the linked project and click above the rotating box, you will see the new boxes fall fine (well nearly fine, there are some oddities when you hit the rotating box at certain angles) but if you comment back in line 29 and comment out line 30 to rotate the group instead the physics doesn’t seem to rotate correctly and the new boxes will land on an invisible physics body. [import]uid: 5833 topic_id: 5028 reply_id: 16511[/import]

presumably when you rotate the image group, you’re not actually also rotating the gravity. won’t this affect things?
[import]uid: 6645 topic_id: 5028 reply_id: 16592[/import]

Hi! Sorry to hijack but I am facing the same issue as NayGames. Has this been confirmed as a bug or are there any workarounds?

I have found another forum post with a similar issue.

https://developer.anscamobile.com/forum/2011/03/14/physics-and-groups [import]uid: 33862 topic\_id: 5028 reply\_id: 29139[/import]

Hey,

I have just yesterday added in some rotation helpers to the code, however haven’t made a release yet (haven’t made one for a while actually, trying to wait till I have something bigger in it) but if you can get access to the SVN then you should be able to get those fixes.

However I can’t guarantee they will solve your issues as they don’t fix the weird physics in groups issue that for quite a while I’ve been thinking was a Lime only issue however after reading that thread you just linked me it is clear that it is happening outside of Lime too. And from the sound of that thread it wasn’t always like this.

I will try to get Ansca more aware of this issue to see if they can shed some light on it. [import]uid: 5833 topic_id: 5028 reply_id: 29141[/import]

The hybrid mode does not work well with rotation and scaling. The actual physics will rotate fine if in a group but the hybrid mode will not overlay correctly.

The hybrid mode is only designed as an aid to setting up your collisions and cannot be used reliably with rotations and I would recommend that on a device it is disabled as it has quite a large processor overhead.

As for map rotations, ive had not issues with Lime as such but in general you will notice artefacts at the edges of the tiles when at certain angles due to a number of things not necessarily related to Lime but how openGL / Corona works.
As far as physics goes, Ive had a lot of discussions with Ansca about how and why things happen and the limitation involved. The best thing not to rotate objects with physics manually. Insert everything into one group and rotate the group, everything in the game ( that has physics) should be in this master group. [import]uid: 5354 topic_id: 5028 reply_id: 29144[/import]

Yea it’s that limitation/issue about having all physics bodies in a single group that is causing issues, I’m thinking how things could be sorted in Lime so that could be done. [import]uid: 5833 topic_id: 5028 reply_id: 29258[/import]

@Matthew Pringle: Weirdly, I am getting the opposite behaviour than the one you described. The hybrid mode shows the layout of where the physics should be nicely, i.e. rotated. But the actual physics is still in the original position. Kind of similar to the code which I linked in my previous post. I will try some more tweaking in the next few days.

@GrahamRanson: I did put everything in one group as suggested in another post but to no avail. [import]uid: 33862 topic_id: 5028 reply_id: 29334[/import]

I have now noticed that display group does not play a part in the wrong physics in my code. The thing is, if I rotate the ground from a different axis , the physics will not move.

Example:

[lua]local physics = require( “physics” )
physics.start()
physics.setDrawMode(“hybrid”);

local crate = display.newCircle(180, 0, 10);
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3, radius = 10 } )

local circle = display.newCircle(180, 400, 100);
physics.addBody( circle, “static”, { friction=0.5, bounce=0.3, radius = 100 } )

– rotation from another reference point does not move the physics
circle.xReference = -180;
circle.yReference = -400;
circle.rotation = 30;[/lua]

Anything that I am doing wrong perhaps (hopefully)? [import]uid: 33862 topic_id: 5028 reply_id: 29343[/import]

I figured something out :slight_smile:

This is literally a “game changer” :slight_smile:
ng [import]uid: 61600 topic_id: 5028 reply_id: 60953[/import]

Do tell… :slight_smile: [import]uid: 5833 topic_id: 5028 reply_id: 60962[/import]

I use full 360degree rotation in my game Planetary Command, however I always had the problem that when you rotate the whole environment, the physics do not rotate correctly. I’d say its more of an issue from box2D then corona. One option you could do is give every element a circle physics body then the rotation problem won’t be an issue. (For example if you have a rectangle and rotation the entire environment the rectangle rotation will remain constant based on its initial position even though the actual physics body doe move, so naturally that’s not something you want to happen - but if you set the physic body to circle then it doesn’t matter anymore what its rotation is.) Of course this won’t be helpful to every game but works fine for mine. [import]uid: 66228 topic_id: 5028 reply_id: 72680[/import]

Is anyone fix this problem? [import]uid: 92273 topic_id: 5028 reply_id: 75996[/import]

As long as you keep all your physics objects in one layer I believe you should be ok. [import]uid: 5833 topic_id: 5028 reply_id: 76203[/import]

Right off the bat, I think groups. [import]uid: 61600 topic_id: 5028 reply_id: 47713[/import]

When I release soon, we shall see :slight_smile:
Not using lime, just pure corona sdk (although I have other titles slated for lime)

ng [import]uid: 61600 topic_id: 5028 reply_id: 76212[/import]

Very much looking forward to see what you have come up with and also what your game is :slight_smile: [import]uid: 5833 topic_id: 5028 reply_id: 76215[/import]

Graham, you and a small group of others will get a pre release preview of it :slight_smile:

I’ll be setting up a private viewing for it to demonstrate wtf I’ve been working on for the last 6 months lol.

ng [import]uid: 61600 topic_id: 5028 reply_id: 76240[/import]