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

Unexpected "Body" returned from RigidBody2D.body_entered(body) signal with Rapier Physics #178

Closed
paklong opened this issue Aug 3, 2024 · 5 comments · Fixed by #179
Closed
Labels
bug Something isn't working

Comments

@paklong
Copy link

paklong commented Aug 3, 2024

Describe the bug

When a RigidBody2D collides with a StaticBody2D, the body_entered(body) signal should provide the "body" as the StaticBody2D. However, using Rapier Physics, it incorrectly returns the RigidBody2D instead.

To Reproduce

  1. Create the Wall:
    -Create a Node2D named "Wall".
    -Add a StaticBody2D as a child of "Wall".
    -Add a Sprite2D with the Wall image as a child of the StaticBody2D.
    -Add a CollisionPolygon2D from the Sprite2D toolbar as a child of the StaticBody2D.
    -Attach the following script to the StaticBody2D:
extends StaticBody2D

func _to_string() -> String:
    return "WallBody"
  1. Create the Ball:
    -Create a Node2D named "Ball".
    -Add a RigidBody2D as a child of "Ball".
    -Enable Contact Monitor and set Max Contact Reported to 1.
    -Add a PhysicsMaterial to the RigidBody2D and set Bounce to 1.
    -Add a Sprite2D with the Ball image as a child of the RigidBody2D.
    -Add a CollisionPolygon2D with a CircleShape2D as a child of the RigidBody2D.
    -Attach the following script to "Ball":
extends Node2D
@onready var rigid_body_2d: RigidBody2D = $RigidBody2D

func _ready() -> void:
    rigid_body_2d.body_entered.connect(_on_body_entered)

func _on_body_entered(body):
    print ('Entered from node')
    print (str(body))

-Attach the following script to the RigidBody2D:

extends RigidBody2D

func _to_string() -> String:
    return "BallBody"
  1. Create the Main Scene:

-Create a main scene.
-Add the "Wall" and position it near the bottom of the scene.
-Attach the following script to the main scene:

func _ready() -> void:
        var ball = preload("res://Ball.tscn").instantiate()
        ball.position = Vector2(551, 96)
        call_deferred("add_child", ball)

Expected behavior
Using GodotPhysics2D, when the "Ball" bounces off the "Wall", it prints:

Entered from node
WallBody

This is the expected behavior.
screen-recorder-fri-aug-02-2024-20-24-25.webm

However, when using Rapier Physics, when the "Ball" bounces off the "Wall", it prints:

Entered from node
BallBody

screen-recorder-fri-aug-02-2024-20-26-45.webm
This is incorrect. The body sent from _on_body_entered(body) should be "WallBody" instead of "BallBody".

Additionally, the last bounce did not trigger _on_body_entered(body).

Environment:
-OS: Microsoft Windows 10 Home
-Version: 10.0.19045 Build 19045
-Godot Version: 4.3rc2 (also tested on 4.2 and 4.3rc1 with the same result)

Example project(zip)
https://drive.google.com/file/d/15y4xSufl-TudEPx96C8o8-U5siQV_OMW/view?usp=sharing

@paklong paklong added the bug Something isn't working label Aug 3, 2024
@Ughuuu
Copy link
Contributor

Ughuuu commented Aug 3, 2024

Can you instead upload the file directly on github? As it is now it's on google drive and i don't have access to it.

@Ughuuu
Copy link
Contributor

Ughuuu commented Aug 3, 2024

Also, what version of the Rapier plugin are you using?

@paklong
Copy link
Author

paklong commented Aug 3, 2024

Can you instead upload the file directly on github? As it is now it's on google drive and i don't have access to it.

I can't upload here due to the zip size is larger than 25MB.
I've created a repo to reproduce the issue.
https://github.com/paklong/ball_bounce_rapier

Also, what version of the Rapier plugin are you using?

Rapier Physics - Cross Platform Determinism
Version: 0.7.23

@Ughuuu
Copy link
Contributor

Ughuuu commented Aug 3, 2024

A solution would be to remove the addons folder as I can put that manually(in future). I have access to the repo, checking it.

@Ughuuu
Copy link
Contributor

Ughuuu commented Aug 4, 2024

I have implemented a fix, will merge it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants