How to detect if a bullet created with the "Bullet Shower" Method is colliding with a TileMap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kocholes
:warning: Old Version Published before Godot 3 was released.

Hi everybody!

I have an Array with bullets created with the “Bullet Shower demo” method. I was able to determine collisions with enemies (they have an Area2d as a child node), but can’t figure out how to determine collision with the walls, floor, etc. (TileMap).
It’s important for my game to handle bullets efficiently, because there will be a lot of them.

Tanks in advance and sorry for my English., Is not my first Language.

I guess you should check raycasting. http://docs.godotengine.org/en/latest/tutorials/ray-casting.html

Bojidar Marinov | 2016-03-07 11:30

:bust_in_silhouette: Reply From: Aaron

A few things:

  • Are your bullets RigidBody2Ds or KinematicBody2Ds?
  • Do you need separate handling for hitting different types of tiles, like different reactions for hitting walls vs hitting floors?
  • Did you remember to add bodies and collision shapes to your tiles when creating your TileSet?

I made a shooter that used tile maps once, where my bullets were KinematicBody2Ds. In the script attached to the bullet scene, whenever a bullet collided with something I used the bullet’s get_collider method to get the object it collided with, then used extends to check its class.

const actor_class = preload("res://scripts/actors/actor.gd")

func _fixed_process(delta):
	var velocity = direction * speed * delta
	move(velocity)

	if is_colliding():
		var collider = get_collider()
		if collider extends actor_class:
			collider.damage()
			explode_actor()
		else:
			explode_wall()

		queue_free()

That said, if the bullet hits a wall I believe get_collider will return the tile’s StaticBody2D, and not the tile map itself. You can work out what tile got hit though using the collision’s location.

very nice expose.thats my doubt too before

you expose we can load from scripts,so can work better with separations collisions objects on game.

TAHNK YOU VERY MUCH :wink:

linuxfree | 2016-08-21 21:28