Collision not working in my project ....

MrToastMrToast Posts: 5Member
edited August 2016 in 2D
I'm creating a space shooter but I got a problem with collisions between the player and the aliens.
This is the problem:
https://www.dropbox.com/s/ptris1gn1rlg8be/Invaders%2022_08_2016%2020_35_52.png?dl=0

The aliens get stuck if they hit the top of the ship,if they hit the left or the right border they get freed (this is what I need)

This is the player script:
extends KinematicBody2D

var root

var ship_speed
var muzzle_wpn = []
var lifes = 0

var bulletTime1
var bulletDelay1
var bulletRes1

func _fixed_process(delta):	
	if is_colliding() and get_collider().is_in_group("enemy"):
		get_collider().destroy()
		remove_life()
	pass
	
func remove_life():
	lifes -= 1
	if(lifes <= 0):
		#kill player,goto retry for coins OR open shop OR open mainmenu
		#Play death animation
		print("player dead")
	else:
		get_parent().get_node("HUD").update_lifes(lifes)
		get_node("animator").play("hit")
	pass
	
func _ready():
	root = get_node("/root/global")
	lifes = root.maxLifes
	lifes = 5 #test
	muzzle_wpn = root.shipWpns
	ship_speed = root.shipNormal
	bulletDelay1 = root.getWpnDelay(muzzle_wpn[0])
	bulletRes1 = root.getWpnResource(muzzle_wpn[0])
	bulletTime1 = bulletDelay1
	set_fixed_process(true)
	pass
And this is the alien script:
extends KinematicBody2D

var root
var hp

var bulletDelay
var bulletTime = 0
var bulletPref

var alienSpeed
var alienWidth
var alienPoints = 1

func getPoints():
	return alienPoints

func destroy():
	self.queue_free()
	pass

func _fixed_process(delta):		
	self.move(Vector2(0,delta*alienSpeed))
	
	if self.get_global_pos().y > 1280:
			print(get_global_pos())
			self.destroy()
			
	if bulletTime >= bulletDelay:
		var inst = bulletPref.instance()
		inst.set_pos(get_node("muzzle").get_global_pos())
		get_parent().get_node("bullets").add_child(inst)
		bulletTime = 0
	else:
		bulletTime += delta
	pass

func hit(damage):
	hp -= damage
	if hp <= 0:
		destroy()

func _ready():
	root = get_node("/root/global")
	alienSpeed = root.shipNormal
	bulletDelay = rand_range(root.wpnNormal*2,root.wpnNormal)
	bulletPref = load("res://prefabs/weapons/laser(enemy).scn")
	hp = root.getAlienHP(1)
	alienWidth = get_node("sprite").get_texture().get_width()
	set_fixed_process(true)
	pass
Here the collisions:
https://www.dropbox.com/s/z871yz3ljc4p1v2/Godot%20Engine%20-%20Invaders%20-%20classic_ship.scn%2022_08_2016%2020_50_21.png?dl=0

Answers

  • MrToastMrToast Posts: 5Member
    Answer ✓
    I solved the problem calling the function destroy() inside the alien when it hits the player
Sign In or Register to comment.