Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | bikereczek |
Hi there.
I’m beginning Godot’s programmer. I’ve problem with collision in my Tower Defense game.
WarScreen.tscn
WarScreen = Control
----Path2D = Path2D
Script Path2D.gd:
extends Path2D
onready var EnemyScene = preload("res://War/PathFollow.tscn")
var StartFirstEnemy = false
var Enemy = null
func _process(delta):
if StartFirstEnemy == true:
for i in Enemy:
i.set_offset(i.get_offset() + 70 * delta)
if Global.ClickStart > 0:
var x = EnemyScene.instance()
self.add_child(x)
StartFirstEnemy = true
Enemy = get_children()
PathFollow.tscn
PathFollowEnemy = PathFollow2D
Script PathFollow2D.gd:
extends PathFollow2D
func _ready():
var enemy
if Global.WhatOpponents == 0:
enemy = preload("res://EnemyUnits/Goblin.tscn")
if Global.WhatOpponents == 1:
enemy = preload("res://EnemyUnits/Orc.tscn")
var x = enemy.instance()
self.add_child(x)
Goblin.tscn
Area2D = Area2D
----GoblinSprite = Sprite
----collision_shape = CollisionShape2D
Orc.tscn
Area2D = Area2D
----OrcSprite = Sprite
----collision_shape = CollisionShape2D
Tower.tscn
Tower = Node2D
----detection_area = Area2D
--------collision_shape = CollisionShape2D
----attack_speed = Timer
Script Tower.gd:
extends Node2D
onready var mob = preload() # <-???
var targets_within_range = []
signal shoot_projectile
func _on_detection_area_area_entered(area):
# Everything is good to this point.
if "mob" in area.name:
targets_within_range.append(area)
func _on_detection_area_area_exited(area):
if "mob" in area.name and targets_within_range.size() > 0:
targets_within_range.erase(area)
func _on_attack_speed_timeout():
if targets_within_range.size() > 0:
var projectile_origin_pos = position + Vector2(32, 32)
emit_signal("shoot_projectile", projectile_origin_pos, targets_within_range[0].position)
In script ,Tower.gd" it tracks down collision, but it dosen’ t track down what is it? - Orc or Goblin?
It dosen’ work:.
if "mob" in area.name:
I try substituted other things instead ‘‘mob’’, but it also doesn’t work.
This problem has harrowed me for week.
Please help me.
Thank you in advance.