Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | linuxfree | |
Old Version | Published before Godot 3 was released. |
I have a space_ship with laser created instance then the enemy colliding with just laser but no colliding with space_ship.Collision mask working. Enemy nothing when colliding with space ship.Enemy decrease energy from space ship but enemy don’t deleted with queue_free()
node and in function enemy node is_colliding()
detect only laser ship but no to ship. Ship, Laser_ship and Enemy are KinematicBody2D
1- Space_ship laser instance function
if (Input.is_action_pressed("ui_select")):
timer_shoot = timer_shoot + delta
if (timer_shoot > 0.23):
laserCount = laserCount + 1
var laserInstance = laser.instance()
laserInstance.set_name("Laser" + str(laserCount))
add_child(laserInstance)
laserInstance.set_owner(self)
laserInstance.set_pos(get_pos() + Vector2(0, -85)) #posição do laser
get_node("Laser" + str(laserCount) + "/KinematicBody2D").add_collision_exception_with(get_node("."))
timer_shoot = 0
## detect if space ship colliding not working for Enemy - COLLISION MASK working
if (get_node(".").is_colliding()): # thats for rocks only
# kinSpeed = Vector2(0,0)
# Globals.set("gameLevel", false)
# get_node("AnimatedSprite_ship2").hide()
# ship_energy = 100
get_node(".").move_to(Vector2(384,1100))
ship_energy -= 1
print("Energy :", ship_energy)
2 - Laser function
extends Node
var laserSpeed = -1366 # this a size of Y coordenate screen
func _ready():
set_fixed_process(true)
# get_node("KinematicBody2D").move_to(Vector2(384, 1200)) no need more
func _fixed_process(delta):
get_node("KinematicBody2D").move(Vector2(0, laserSpeed * delta))
if (get_node("KinematicBody2D").get_global_pos().y <= 0 or get_node("KinematicBody2D").is_colliding()): #only for rock
if (get_node("KinematicBody2D").is_colliding()): # only for rock
get_node("KinematicBody2D").get_collider().duraRock -= 1 # decrease rock durable
get_node(".").queue_free() # laser out of game
func set_pos(position):
get_node("KinematicBody2D").set_pos(position)
3 - Enemy instanced give me a lot on screen - but Colliding just with laser but not with Space_ship
if (duraRock == 0):
if Globals.has("score"):
Globals.set("score", Globals.get("score") + points) # increment score 30
get_node(".").queue_free() # delete all node
# working collision mask with space_ship but cant check is_colliding( ) function
if (get_node(".").get_global_pos().y > 1366 or get_node(".").is_colliding()): #only for rock
get_node(".").queue_free() # delete Enemy from screen
print("Enemy Colliding")
I NEED queue_free
enemy node when collide with space_ship
if possible help me
thanks