+1 vote

Once upon a time my PlayerChar node only had one collision box that interacted with enemy attacks and walls. The PlayerChar could walk right through enemies though. Instead of making the enemies hurt the player or making it so the PlayerChar couldn't walk through the normal collision boxes, I'd rather the PlayerChar and enemies to have a slightly smaller collision box that they couldn't walk through:

enter image description here

I unsuccessfully tried pulling this off by attaching a KinematicCharacter2D node with a CollisionPolygon2D to both enemies and the player and giving the new Kinematics their own Layer and Mask, but that didn't work. Here's how the PlayerChar scene looks like:

enter image description here

Before a move forward, I wish for advice on how to approach this.

in Engine by (32 points)

I'm not sure to understand the objective of the second collider.

You want player and enemies collide each other and both collide the level or player "transparent" to enemies?

ps: That secondary body won't be affected by move (in the sense of triggering it's physics collisions) and will work as a regular kinematic body, useful for pushing rigidbodies but not for kinematic collisions.

I'm not sure to understand the objective of the second collider.

It's just supposed to block the player, just like a wall. Difference is that the player and enemies use that second collider so they can get up a little closer to each other compared to regular walls.

1 Answer

+1 vote

It won't work because collision detection wont be updated on the inner kinematic body (is not a joint but 2 separate bodies, one moving, the other dragged by the parent), you can add an Area2D instead and simulate a collision with area_enter signal or get_overlapping_areas.

But I think that will work better if the small body is the parent kinematic and the bigger is an area (or a set of raycasts).

And there is a way to "move" 2 bodies at once but is kind of hacky:
Put the children inside a plain Node, the children of Node will not be affected by parent's transformations.


Then, when you move the body in the script, you will need to move "Node/KinematicBody2D" too, and check both for collision.
I don't like it, it could get messy in some cases, but may work.

by (7,888 points)

that's a cool idea, let me try this too, thanks eons

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.