4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
9.04k stars 786 forks source link

Physics custom hitbox not rescaled #1812

Open PascalLadalle opened 4 years ago

PascalLadalle commented 4 years ago

In the physics example, there are three floor instances. One flat and full size, one slim and flat, and the other one slim and angled. I edited the physics hitbox of the floor object to make it one pixel smaller (799*99). Then, the slim floors have their original scale, not graphically but in terms of Physics hitboxes. The balls are on them: image

Custom physics hitbox should resize along with the size of instances, right?

The issue is the same with "Physics 3.0"

GD5b95 Win10

4ian commented 4 years ago

They should yes, I suspect their origin point is somehow messed up. Can you share the project?

PascalLadalle commented 4 years ago

Here goes: buggedphysicshitboxrescaled.zip

PascalLadalle commented 3 years ago

So, I see there's an action to scale the physics shape scale when it's custom. Was it already there when I created this report? 🤔 image

Either way, it's very inconvenient for me not to be able to scale width and height separately. I see the old Physics had this. Could it be added to Physics 2 as well? image

planktonfun commented 1 year ago

Here's a workaround in javascript if anyones interested

const SpriteObject = objects[0];
const PhysicsObject = SpriteObject.getBehavior('Physics2');
const Vertices = PhysicsObject.polygon.vertices;

const AdjustedVertices = [];
for(var c of Vertices) {

    // relate position to object scale
    const scaledCoordinates = [
        c[0]*SpriteObject._scaleX,
        c[1]*SpriteObject._scaleY
    ];

    AdjustedVertices.push(scaledCoordinates);
}

PhysicsObject.polygonOrigin = "Origin";
PhysicsObject.polygon.vertices = AdjustedVertices;
PhysicsObject.recreateShape();
Silver-Streak commented 1 year ago

I seem to be able to rescale custom masks for physics in 5.1.157 without issue. @PascalLadalle do you still experience this in your test project?

AlexandreSi commented 1 year ago

Closing this since I think it's ok now. But I tested the project @PascalLadalle joined above and it doesn't work but the project was a bit weird I think (there was multiple directions in the animation of the concrete wall though it's normally not possible to add directions).

planktonfun commented 1 year ago

Tested not working for me, Version: GDevelop is: 5.2.166 (editor full version: 5.2.166-2496fc3eefd3a25c7a452d10b751395e9a6b6e13, core version: 4.0.99-0-release)

reference:

https://github.com/4ian/GDevelop/assets/1837825/efbdec53-0874-47ab-9760-d975ba5bdbd6

AlexandreSi commented 1 year ago

I may have done a bad test then! Thanks for checking, I'll have another more watchful look

AlexandreSi commented 1 year ago

Here is what I found: when using either of the 3 predefined shapes (Circle, Box and Edge), if you don't specify custom dimensions (Width, Height, Lenght or Radius), the Box2D shape is scaled to match the parent object size.

But that's not the case for the Polygon shape: the points defined by the user are not matched to the parent default width and height so that if you change the dimension of said parent are changed, the polygon is too.

I'm not sure why it was not implemented at first but I guess this should be the default way. For this to be implemented, we would need the default width and height of the object in the createShape method.

BUT, there is no notion of a default width/height for a sprite object.

So I think that if someone wants to scale the shape of body, this person should set up actions and conditions that make sure the shape always has the same scale as the parent sprite object (using the action "Shape scale") => There is currently no way of setting the scale separately on X and Y axis so we might need 2 new actions for both.

d3is commented 1 month ago

Looks like this is still an issue with: 5.4.205 (editor full version: 5.4.205-98befc80009883d9131c6b06a40338adf7a61b86, core version: 4.0.99-0-release) I am using Physics2 behavior with a Polygon shape and Polygon Origin set to Center. If the sprite is scaled in any way, the collision polygon does not get scaled. The GDevelop docs state: If you set the polygon origin to Center and scale the shape down, the vertices will be scaled down to/in-direction-of the object center. But, this isn't working as documented.

AlexandreSi commented 1 month ago

Indeed this issue has not been worked on. If you need a workaround, please check this https://github.com/4ian/GDevelop/issues/1812#issuecomment-1328339430. You shall use a Javascript code event and also select the objects you want the event to have access to.