I am new to the Defold Engine (like it very much so far) and following the “Getting Started”-Tutorial presented to me in my Dashboard.
(I am using the Preview Version of the Defold 2 editor.)
At Step 6, where we set up Ground Physics and Collisions, I am stuck because I get collisions where I shouldn’t get one.
Thanks to another Forum Post I figured how to enable “Debug” and thanks to that, I saw, that the Collision Shapes of the hero and the platform_long are strangely off from where I set them in the editor.
The small platform seems fine, but everything else is somehow totally off.
I tried to fix it for some time and figured, if I position the platform_long with the center of the left part at X = 0, it fits also ingame:
This looks really strange. What’s surprising is that for the short platform the collision shape is in the correct position. I would have expected all or none to be offset.
As @Pkeod suggested please zip the whole project, or if it’s created from the Defold Dashboard then go ahead and invite me (bjorn.ritzl@king.com) so that I can take a look.
Weird, apparently the collision object components are not keeping their offset. If you set the position of the collision object components to 0, 0, 0 and move the shapes into the right positions then it is fine. The short platform worked correctly because its collision object was already at 0, 0, 0. It must be a bug.
[edit] Oh, collision object components don’t have a position in Editor 1 . . . maybe the bug is that position and rotation are being used at all in Editor 2. (like it does with script components)
Thanks Ragnar. @multicoderdev: The solution is to not modify the collision object position and instead manipulate the collision shape positions to align them with the sprites.
The only thing that have attributes is the “go” that have an x of 360. It looks like the sprite gets dubble transforms. Once from the “go” and then again from the “collisionobject” or something like that. It doesn’t feels right to me, but it is this the expected behavior?
Hmm, that looks weird. I’m guessing that the collision object is dynamic? Dynamic collision objects attached to a game object will override any position set by either scripts or as a result of the game object being added as a child of another go (as is the case in your example where go1 with the collision object is a child of go).
Yes, the object is dynamic. I start with this collection, so there are no scripts running, what you can see in that collection is everything in the scene. I know it overrides the position and that you can only effect it by force, but shouldn’t that mean that even if it changed position of its parent go shouldn’t that also effect the sprite? Does it effect it twice?
Does this mean that you can’t have an offset for all your dynamic objects but most have all parents zeroed out and only set the position on the direct object?
In your situation, with a game object - with a dynamic body - set as a child to another game object, it won’t work as you might think. The sprite component on “go1” will inherit the transform from both “go” and “go1”, as you would normally expect, but “go1” is moving independently, rather than keeping its local position like a normal child. It means if “go” is moved from (0, 0) then the sprite will be offset from it’s parent, “go1”.
Basically you don’t ever want a G.O. with a dynamic body to be the child of another G.O…