export var + inherited scene

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

Hello guys!

I have a base Scene “Enemy” with Area2D “detect_radius”.
In script i do:

export (int) var detect_radius
func _Ready():
$DetectRadius/CollisionShape2D.shape.radius = detect_radius

I inherit from this Scene and Change the value of the Export var.
Enemy to 30.
Endboss to 50.

Now to the Problem… in my tree if i put it like this.

-Enemy
-Endboss
Both of them has 50.

Otherway around.
-Endboss
-Enemy
Both of them has 30.

Do i understand something wrong?
Or do i Need the Area2D in every Scene and not inherit from Enemy?

:bust_in_silhouette: Reply From: Gabriel

The problem is that they are sharing the same collision shape.
To fix this you would have to do something like this:

export (int) var detect_radius

func _ready():
    var circle = CircleShape2D.new()
    $DetectRadius/CollisionShape2D.shape = circle
    $DetectRadius/CollisionShape2D.shape.radius = detect_radius

Related video with your problem: Godot 3.0: Top-down Tank Battle - Part 5

Hello and thanks!
Thats how i did it shortly after i asked.

But didnt saw my Question after asking it and couldnt delete or replay myself.

MaggoFFM | 2019-09-25 19:18