What i want is that in buildMode the collision of the Building do not affect other shapes. Only be a visible Sprite to show where the Building can placed. If the building is placed then it needs the collision back again to prevent players to run through it.
My nodes:
Node2D [Main]
TileMap [Map]
KinematicBody2D [Player]
Sprite [Image]
Camera2D
CollisionPolygon2D [Collision]
Node2D [Buidlings]
KinematicBody2D [Building01]
Sprite [Image]
CollisionPolygon2D [Collision]
Szenario (short to explain):
# Variables
var allowPlace = false
var buildMode = false
# on BuildMode Start:
buildMode = true
Building01.get_node("collision").set_trigger(true)
# on Fixed Process:
if buildMode:
Building01.move_to(get_global_mouse_pos())
var b = Buidling01.get_node("Collision")
# How to do that here in a right way to check overlapping or collision ?
if (b.is_colliding() || b.get_overlapping_bodies().size() > 0):
allowPlace : false
else:
allowPlace: true
# on Mouseclick
if allowPlace:
buildMode = false
Building01.get_node("Collision").set_trigger(false)
else:
print("OMG! You cant place a building on a Player or a collision map tile!")
Well I tried to use an Area2D instead of a KinematicBody2D for the Building01. There i can check if the Building01 is over another Shape but then i still have no collission when it is placed. That means my Player can run through the Building (although is_trigger equals false when placed).
If i use a KinematicBody2D then i cant really check if the Building is acutally over a Player or StaticBody2D with collision (while buildMode) but here i have the collision what prevents the player to run through the building.
I also tried to use a KinematicBody2D AND the Area2D in the [Building01] Node. But then they detect itselft as overlapping shape what will always return the wrong value for allowPlace.
I´m really confused how to fix that problem. Can anyone help me here ?