CollisionShape2D is not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bikereczek

Hi there.
I’m beginning Godot’s programmer. I’ve problem with collision in my Tower Defense game.

WarScreen = Control
----Path2D = Path2D


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()
		StartFirstEnemy = true
		Enemy = get_children()

PathFollowEnemy = PathFollow2D


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()

Area2D = Area2D
----GoblinSprite = Sprite
----collision_shape = CollisionShape2D

Area2D = Area2D
----OrcSprite = Sprite
----collision_shape = CollisionShape2D

Tower = Node2D
----detection_area = Area2D
--------collision_shape = CollisionShape2D
----attack_speed = Timer


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

func _on_detection_area_area_exited(area):
	if "mob" in and targets_within_range.size() > 0:
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 ," it tracks down collision, but it dosen’ t track down what is it? - Orc or Goblin?

It dosen’ work:.

if "mob" in

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.

:bust_in_silhouette: Reply From: Moldor2

The test statement should be something like this…
for(Areas) in area: if == "mob": #DO SOMETHING

I know this, but what do i have to load as ,mob’'?

bikereczek | 2020-09-25 15:15

Try adding orcs to a group called orcs and add goblins to a group called goblins and then test if the area is in group orcs or if it is in group goblins

Moldor2 | 2020-09-29 12:29

Thanks, it works. I also know what I had to do in order to “if mob in” works.
But I have a new problem - in script “” positions “Orc” and ''Goblin" are (0,0).
In my opinion everything is good.
But I need positions from script “” (var i.set_offset).
I need this to tower’s shot func (_on_attack_speed_timeout() - var target_within_range[0].position).
How to do this?

bikereczek | 2020-09-30 22:29

Sorry. Script “Path2D” (not

bikereczek | 2020-09-30 22:35