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

Get specific collisionShape when KinematicBody has multiple collisionShapes #446

Closed
AlexZan opened this issue Feb 6, 2020 · 7 comments
Closed
Labels

Comments

@AlexZan
Copy link

AlexZan commented Feb 6, 2020

Describe the project you are working on:
I am working on a block building vehicle prototype. A vehicle can have thousands of blocks. There can be many vehicles per game.

I have one kinematic body for a vehicle so that I can move it, then I load all the blocks in as collision shapes with mesh instances within them.

Describe the problem or limitation you are having in your project:

I cannot seem to get reference to the collision shape I am "hitting": My player has a melee attack block, it has an attack script with an area and a collision shape.

I have tried get_overlapping_bodies()

and the signal

func _on_Area_body_shape_entered(body_id, body, body_shape, area_shape): print(body_id, body, body_shape, area_shape)

I am always getting reference to just the kinematic body. But it does not seem possible to get the collision body I am actually hitting.

Describe how this feature / enhancement will help you overcome this problem or limitation:

provide reference to the specific collision shape when a kinematicbody has multiple collision shapes

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

not applicable

Describe implementation detail for your proposal (in code), if possible:

not applicable

If this enhancement will not be used often, can it be worked around with a few lines of script?:

The work around would be to check each collision body for collision, but thats on potentially 10,000+ blocks. Also I dont want my blocks to have any attack checking responsibility.

Is there a reason why this should be core and not an add-on in the asset library?:

It is fundamental to reference a node responsible for collision, no matter what node setup.

@Jummit
Copy link

Jummit commented Feb 6, 2020

This seems like a bug. Report it on the Godot Engine Github:
https://github.com/godotengine/godot/issues

@AlexZan
Copy link
Author

AlexZan commented Feb 6, 2020

Well the function and signal are working as intended it seems, there just is no feature currently to get reference to the collision shape

@AlexZan AlexZan changed the title Can't get specific collisionShape when KinematicBody has multiple collisionShapes Get specific collisionShape when KinematicBody has multiple collisionShapes Feb 6, 2020
@KoBeWi
Copy link
Member

KoBeWi commented Feb 6, 2020

body_shape_entered( int body_id, Node body, int body_shape, int area_shape )
Emitted when a physics body enters, reporting which shapes overlapped.

That totally sounds like what you need. Then use shape_owner_get_owner(shape_find_owner(body_shape)) to get the shape.

@AlexZan
Copy link
Author

AlexZan commented Feb 6, 2020

@KoBeWi that seems to provide the id of the collision shape that is attached to the player Area, not the other "enemy" collision shape. Which I already have since my player is "attacking/hitting" from the area collision shape. What I need is the collision shape that my collisions shape hit. (one or more, of many, since the enemy kinematic body can have many collision shapes as children)

@KoBeWi
Copy link
Member

KoBeWi commented Feb 6, 2020

Uh, I think it should've been
body.shape_owner_get_owner(body.shape_find_owner(body_shape))
Anyways, the function does what you want to achieve. But you need to use it correctly.

@AlexZan
Copy link
Author

AlexZan commented Feb 6, 2020

@KoBeWi I had tried this before also, this only gives the id of first collision shape, no matter which collision shape i am entering

@KoBeWi
Copy link
Member

KoBeWi commented Feb 6, 2020

So yeah, I tested it and there's a bug. Also turns out a similar bug was already reported: godotengine/godot#19290
Closing this.

@KoBeWi KoBeWi closed this as completed Feb 6, 2020
@KoBeWi KoBeWi added the archived label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants