+2 votes

Hey,
I am trying to make a 2D game and I have a KinematicBody2D character that has a small collision shape specifically for the walking animation. (I want the player to walk up until his knees against a wall as if he was standing in front of it. When I first made it, the player would collide as soon as his had hit a wall.)

Now I want to let the user interact with objects for example picking something up. The problem is that it only works with the collision shape that I made for the walking animation. This means that the player can only pick up items with its knees.
I tried to add a second collision shape to player but it will then register both collision shapes which solve this problem but then the player would again bump its head against a wall instead of its knees.

Which brings me down to my actual question:
How can I have an object with multiple collision shapes with separate functions?

In my case:
Player has collision shapes walkcollision that collides with walls only and interactcollision that collides only with ground objects.

in Engine by (17 points)

1 Answer

+1 vote
Best answer

I think you can make many collision and
enter image description here

Then using disable property of collison shape for active or deactive them
enter image description here
enter image description here

by (316 points)
selected by

But how do I then implement it for the different objects?
If I disable for example the interactcollision then it won't interact with any items. When do I need to turn the collisions on and off because I only know when to disable it after I already collided with a wall, when it is too late.
I want the collision shapes of wall and walkcollision and of item and interactcollision to collide only.

You may use Area2D for additional collision
enter image description here

change Collision Layer of Item to Pick Up
change Collision Layer to Pick Up

Change MaskCollison of Interact_Area to Pick Up
enter image description here

Change MaskCollison of Player to Terrain
enter image description here

Then use signal areaenter of Item to detect InteractArea

I works now thank you.

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 Frequently asked questions and 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 [email protected] with your username.