Skip to content

Potential bug in PhysicsBody2D.gd #304

@Daniel-Cortez

Description

@Daniel-Cortez

(I'm not really sure if this is actually a bug or not (hence "potential"), but still reporting here, as such mistakes can be hard to find otherwise.)

I was lurking through the code in PhysicsBody2D.gd and accidentally found what seems to be a pretty sneaky mistake.

if move_and_collide(rayHitVec-(normHitVec*($HitBox.shape.size.y/2))-Vector2(0,yGroundDiff).rotated(rotation),true,true,true):

According to the documentation for move_and_collide(), the 3'rd argument (safe_margin) is supposed to be float, not bool.

Now what makes this mistake "sneaky" is that GDScript automatically (implicitly) converts that value from bool to float (in this case, from true to 1.0, while the default value of that argument is 0.08), never warning about a type mismatch, which is why the abovementioned line essentially becomes

if move_and_collide(rayHitVec-(normHitVec*($HitBox.shape.size.y/2))-Vector2(0,yGroundDiff).rotated(rotation),true,1.0,true):

I'm not very well acquainted with the physics code, so I'm asking more experienced users/devs: is argument safe_margin here really supposed to be 1.0? If not, what would be the best way to fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions