I have a problem with the engine Godot, with the errors "body set shape disabled" and "body set shape as one-way collision".
In my project I have built four scenes:
The
platform
scene formed by (StaticBody2D
which has as child objects(CollisionShape2D
,Sprite
,Position2D
,Area2D
which in turn has a child object(Collisionshape2D
))The
missile
scene formed by (RigidBody2D
which has as child objects(CollisionShape2D
andSprite
));The
spaceship
scene formed by (Kinematicbody2D
which has as child objects(Sprite
andCollisionShape2D
));The
main
scene which has as root nodeNode
and as child objects: (platform and spaceship).
Moreover I have two scripts: one in the spaceship
scene, on the Kinematicbody2D
node; and then in the platform
scene on the StaticBody2D
node.
Basically when I start the game there is the platform
at the top center and then there is the Area2D
(with the CollisionShape2D
to detect when a body enters the area and then there is also the Position2D
that I set for a position where it should instantiate the missile at runtime).
When a body enters the Area2D
the platform
should instantiate a missile
(which does nothing for the moment).
The problem arises when I direct the spaceship
in the Area2D
and the platform
instantiates many times (more than 200-300 times per second) the missile and this is the moment when the game crashes. I get the errors that I wrote above and then I have to close it.
Spaceship Code:
extends KinematicBody2D
var target
var click
var dir
var collision
var speed = 200
func _input(event):
if event is InputEventMouseButton:
target = get_global_mouse_position()
click = true
func _physics_process(delta):
if click:
dir = position.direction_to(target)
collision = move_and_collide(dir * speed * delta)
if collision:
pass
Platform Code:
extends StaticBody2D
var trigger
var missileScene = preload("res://scenes/Missile.tscn")
var missile
func _on_DangerArea_body_entered(body):
if body is KinematicBody2D:
trigger = true
while(trigger):
missile = missileScene.instance()
$SpawnPosition.add_child(missile)
yield(get_tree().create_timer(3),"timeout")
func _on_DangerArea_body_exited(body):
if body is KinematicBody2D:
trigger = false