I want my bullet to destroy when it hits a tileset wall, but whenever I try it collides with the floor despite the floor not actually having any collision setup. Idk what I'm doing wrong. Here's my code. I've tried other ways to do it, but I don't remember anymore. Thank for your help and time. I should also probably mention this is a top down 2d game. Idk what other info is needed, probably a lot since I gave nothing. So please tell me if u need a screenshot or something, thanks
#Can't make bullet destroy on collision with tileset walls
45 messages · Page 1 of 1 (latest)
Also, I know this way is probably horrible and I have had better ways to do it before, but as I said. I don't remember them. It's been like 6 hours and its 4am for me.
well, that is destroying the node's parent the moment it is not overlapping the player
why are you not using the body_entered signal to catch the collision?
I've tried it. The outcome ends up being the same. (as in that it destroys the object instantly) I assume its because it collides with the player on spawn. But I thought layer masks would fix that and it hasn't. Is there a way for me to find out what body triggered the body_entered signal?
If you give your player a class name (i.e. Player) you can check if body is Player
oh how do you do that? Sorry I just started learning Godot a couple days ago so I don't know anything pretty much.
at the top of your player script under extends put class_name Whatever and then you can check if body is Whatever: do thing
you can also reference any variables if you need it to not be a blanket check say you have multiple bodies of the same class but you only want one to be interactive based on some set condition set a global variable within the class and then verify the variable.
if body.variable == value:
do thing```
Thanks, I'm having some issues. I think it's colliding with itself. My bullet scene is shown below. The characterbody takes care of the movement of the bullet while the Area2D contains the collision code from above. The code said it was colliding with an Area2D. And this is the only area2D in all of my scenes. This is the code for my bullet collision. It's again, not good at all. But I'm kinda just stuck
Thats a masking issue
You need to figure out what sees what
Any effect on a body should be handled by the body and not the colliding object.
So unless the bullet needs to see something, remove its collision mask, and set the mask of the receiving body the same as the layer of the bullet
Then call a function within the bullet to handle any aesthetic things on itself. Animations, queue_free() etc
thats the thing. I'm pretty sure I setup the masks correctly. Both my character body and my area2d on my bullet have this. Making it so it's on its own "Bullet" layer and that it only collides with the tilemap
Is there a reason your bullet needs to see anything?
Well the reason I'm setting this up is because I want the bullet to destroy on collision with tilemap walls and I want it to damage an enemy on hit and also get destroyed afterwards. Right now I'm just setting up the destroy on collision part. If there's another way to set this up, I am 100% fine with changing it
You can still do that. For the script for the destroyable object I'm assuming you're calling get_overlapping_bodies right?
I was originally, but I couldn't get it to work correctly. So after hours of changing it, I'm now at this:
I have this in a seperate Area2D but I don't need the Area2D if the CharacterBody2D can do it
So get overlapping bodies returns an array of any overlapping bodies.
Use a for loop to iterate that array like for body in bodies: body.queue_free()
That should be in the Tile script not the bullet
got it. How would I know if it's a bullet? What does the array save? The name of the object?
if body is Bullet: if bullet is the class name
got it, thank you
np
Doing it this way you can remove any masks from the bullet
Bullet doesn't need to see shit
but bullet needs to be on the same layer as the wall
well what the walls mask is
got it. I got one question thats probably obvious. How do I call get_overlapping_bodies in a TileMap Script?
unless I just add an object that can call it to the tilescene
Okay, I now have this setup on my tilemap
but it always says theres no body overlapping
nvm ignore that, I turned off the collision shape for the bullet because I was using the Area2D for the code on it. It works
Thanks for helping out a bunch, I would have been stuck on this for years. Already took an entire day and I'm doing it for a game jam so time is tickin down lol
Thanks, good luck with anything you might be workin on