magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 0:10:29 GMT
I'm experiencing a very strange issue with child killables. I have a main spaceship Killable that is a rigidbody2D and is set to a layer that can damage the player. This part works fine. If the player collides with the ship then the player is destroyed. Now, this main Killable spawns another killable and is attached to a object in the main Killable's hierarchy (so it's now a child of the main Killable). This child killable is also set to a layer that can damage the player. However, when the player hits this child killable it does not damage the player. Instead, the main Killable takes damage instead. I have a listener with a TakingDamage function on the main killable and this function is being called every time the player touches the child killable.
Note, the reason the main killable is a rigidbody2D is so that the colliders of the child killable will be considered as part of a composite collider for the main killable. Without this, the collision won't occur at all.
|
|
|
Post by DarkTonic Dev on Oct 5, 2017 0:27:27 GMT
You should probably make some changes on the main Killable. Turn on "invincible when has children" and "disable colliders also" under that.
You don't need to worry about different collider types and layers and all that.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 1:10:24 GMT
You should probably make some changes on the main Killable. Turn on "invincible when has children" and "disable colliders also" under that. You don't need to worry about different collider types and layers and all that. I suppose I could solve it that way, but I didn't really want the main killable to be invincible with a child killable. But it looks like you're saying that's not possible at the moment? [EDIT] I tried this approach and it still doesn't work exactly. The main killable doesn't kill the player anymore and hitting the child killable doesn't cause the main killable to take damage, but hitting the child killable doesn't affect the player either so it doesn't die when it's supposed to.
|
|
|
Post by DarkTonic Dev on Oct 5, 2017 1:53:57 GMT
Well the problem may be with your original setup - any child object colliders will automatically ride up and actually fire on parent game objects and not themselves unless the children also have their own rigidbodies. Do they?
Add them if not. If they already have, the best thing is always to turning on Logging for the parent and child Killables and check out everything that gets logged. It will say when it ignores what because of layer filter etc.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 2:44:17 GMT
Well the problem may be with your original setup - any child object colliders will automatically ride up and actually fire on parent game objects and not themselves unless the children also have their own rigidbodies. Do they? Add them if not. If they already have, the best thing is always to turning on Logging for the parent and child Killables and check out everything that gets logged. It will say when it ignores what because of layer filter etc. I can't seem to get this to work. I tried adding a rigidbody2D to the child killable, but it didn't change anything. The effect I'm going for is that the player should be damaged when it touches the child killable. But with the configurations I've tried, it either has no affect at all or it causes the parent killable to get damaged. But the parent killable should never be damaged by the player hitting it. It should only be the other way around.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 2:47:52 GMT
I must have something else wrong. Even if I spawn the killable and don't attach it then it's not causing damage to the player. I must have something messed up somewhere. I'll try to get that fixed first and then see if I can get it working as a child after that.
|
|
|
Post by DarkTonic Dev on Oct 5, 2017 2:50:06 GMT
Yeah, good idea. Use the Killable logging to assist.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 2:58:33 GMT
Yeah, good idea. Use the Killable logging to assist. OK, so it seems like the issue has to do with colliders that are not at the same level in the hierarchy as the killable itself. If there is a collider on the same level then it kills the player, but if a nested object in the killable's hierarchy has the collider then it has no effect. Example: This works: Killable Root (collider here) -Child Object -Grandchild Object This doesn't work: Killable Root (no collider; has rigidbody2d) -Child Object -Grandchild Object (collider here)
|
|
|
Post by DarkTonic Dev on Oct 5, 2017 3:12:25 GMT
Not an issue, just lack of understanding, luckily!
Killable has the collision / trigger event code within Killable (and nothing on sub-Game Objects), so of course that wouldn't work automatically.
If your Killable has a collider in a sub-game object instead of the same game object, you will need to add the Killable Child Collision script to the sub-Game Object with the collider. Then it has a field to tell it which Killable to notify of collision. Drag the parent Killable in there.
We also have a similar script if the renderer is on a sub-Game Object.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 3:14:10 GMT
Not an issue, just lack of understanding, luckily! Killable has the collision / trigger event code within Killable (and nothing on sub-Game Objects), so of course that wouldn't work automatically. If your Killable has a collider in a sub-game object instead of the same game object, you will need to add the Killable Child Collision script to the sub-Game Object with the collider. Then it has a field to tell it which Killable to notify of collision. Drag the parent Killable in there. We also have a similar script if the renderer is on a sub-Game Object. Thanks. I was not aware of the Killable Child Collision script. I was just in the process of making each child with a collider it's own Killable, which seemed to work also. But I think the Killable Child Collision script is probably the more proper solution.
|
|
magique
Full Member
 
Posts: 194
Posts: 194
|
Post by magique on Oct 5, 2017 3:38:59 GMT
Yeah, that did it. I was able to make it all work the way I wanted to by just adding the Killable Child Collision script. Thanks for the help.
|
|
|
Post by DarkTonic Dev on Oct 5, 2017 3:39:46 GMT
Yep, no problem.
|
|