-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Update using_character_body_2d.rst #10675
Conversation
I added an example of an if statement on move_and_slide with collision.get_collider().name to detect collisions with specific object types.
Co-authored-by: A Thousand Ships <[email protected]>
Looks good, but the C# example needs to be updated to match |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but needs someone to verify the C# code as I don't use C#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As is I think the example teaches bad practice. If we want to include an example like this, I left some different directions that the example could go in a comment.
Edit: and to be clear I'm still a casual user when to comes to best practice for GDScript, but the example here seems fragile even to me
if collision.get_collider().name == "TileMapLayer" or collision.get_collider().name == "RigidBody2D": | ||
print("I collided with ", collision.get_collider().name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intention with this whole example?
Is the intention to check if we are colliding with any TileMapLayer or any RigidBody2D? If so, doing so by checking the name of the collider seems fragile and likely to teach bad habits. RigidBodies and TileMapLayers are unlikely to be named exactly "RigidBody2D" or "TileMapLayer". Something like the following is much more robust:
if collision.get_collider() is TileMapLayer or collision.get_collider() is RigidBody2D:
But I'm not sure if we're currently supposed to use type casting in examples in general at this time.
I believe groups are also reasonably idiomatic for this:
if collision.get_collider().is_in_group("Player"):
If the intention is merely to teach that you can use some sort of filtering on the results using the names, I would try filtering by something like "Wall" or "Enemy". But that is really not very robust, since any duplicated/instantiated nodes will have names like "Wall2" or "Wall3".
Closing due to the lack of a response to tetrapod's review. @Nio03 if you want to keep working on this in the future feel free to ping me and I'll re-open this. |
I added an example of an if statement on move_and_slide with collision.get_collider().name to detect collisions with specific object types.