0 votes

I am trying to make a top-down shooter game with a character that can shoot bullets. I have 2 types of walls, ones that stop the bullets and I want to make one that can be destroyed with the bullet. for example, when the bullet touches a tile in the tilemap, that tile will disappear. Is this possible using Godot and if so, can you please help me.

in Engine by (17 points)

i made a way to do it but its very inefficient and doesnt always work. i made a singleton and put a variable for bullet position. then i converted that to tilemap position and deleted any tile that was in that position. the problem is that it only works with the most recent bullet.

for the tilemap

extends TileMap
var bp
func _physics_process(delta):
    bp = world_to_map(global.bullet_position)

for the bullet

extends RigidBody2D
var timer = 1

func _process(delta):
    if timer >= 0:
        timer -= delta
    global.bullet_position = position

if theres any better way please let me know.

1 Answer

+1 vote

Stick an Area2D on the bullet. When the body_entered signal triggers on the TileMap, remove the tile at the position of the area (you'll probably have to play around with offsets to remove the correct tile). Also remove the bullet as well.

by (7,456 points)

thank you so much. i edited the code i currently had and now it works really good. thanks.

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.