I am trying to set a collision polygon between two points, I got the polygon part working already (I can draw arbitrary polygons), but it ignores collision.
Here's how I'm trying to organize the scene:

And here is the code:
extends Node2D
func setup(var click_ini, var click_fin):
#set_pos((click_fin+click_ini)/2)
var coll = get_node("polygon/StaticBody2D/collision_polygon")
var poly = get_node("polygon")
print("Creating static platform")
print(click_ini)
print(click_fin)
var click_ini_b = click_ini
var click_fin_b = click_fin
click_ini_b.y -= 10
click_fin_b.y -= 10
var vecArray=[click_ini,click_fin, click_fin_b, click_ini_b]
coll.set_polygon(vecArray)
poly.set_polygon(vecArray)
func _ready():
pass
When instantiating, the setup function is called and I set up the polygon shape (It works), then I set the collisionpolygon with the same polygon but no collisons are detected when a kinematicbody2d collides.
If, instead of a collisionpolygon I use a regular staticbody it works as intended, the collision detection part isn't the problem, but here's what I'm trying to do anyway:
extends KinematicBody2D
const GRAVITY = 200.0
var velocity = Vector2()
func _fixed_process(delta):
if(is_colliding()):
print("BEEP")
velocity.y = -velocity.y - 20
var motion = velocity * delta
move(motion)
velocity.y += delta * GRAVITY
var motion = velocity * delta
move(motion)
func _ready():
set_fixed_process(true)
I just detect if a ball has collided and deflect it, and it works fine, just not with the polygon.