0 votes

Hello, I am coming from Unity and am finding something I thought would be a very fast and simple test project rather difficult. I am trying to create a script of circles that detect when they collide with other circles, the larger one will absorb the smaller one. But when I resize the collision circle it just stops working all together. here is my code.

extends KinematicBody2D


var radius = 25
var pos = Vector2(0,0)
var col = Color(0,0,0)

var moveSpeed = 3
var movement = Vector2()
var maxSpeed = 4

var isShrinking = false
var isGrowing = false

func _draw():
    draw_circle(pos, radius, col)
    pass


func _process(delta):
    $CollisionShape2D.shape.radius = radius
    $Hit/CollisionShape2D.shape.radius = radius #this is the one with problems


    if Input.is_action_pressed("d"):
        movement.x += moveSpeed
    elif Input.is_action_pressed("a"):
        movement.x -= moveSpeed
    else :
        movement.x = 0

    if Input.is_action_pressed("w"):
        movement.y -= moveSpeed
    elif Input.is_action_pressed("s"):
        movement.y += moveSpeed
    else :
        movement.y = 0


    if Input.is_action_just_pressed("ui_up"):
        radius += 5

    move_and_slide(movement)
    update()

    if isShrinking:
        _shrink()
    if isGrowing:
        _grow()

    pass



func _shrink():
    print("SHRINKING!")

func _grow():
    print("GROWING!")




func _on_Hit_area_entered(area):
    if area.get_parent().radius > radius:
        isShrinking = true
    elif area.get_parent().radius < radius:
        isGrowing = true


func _on_Hit_area_exited(area):
    isGrowing = false
    isShrinking = false

I cant figure out how to do this, I feel it should be very simple but I cant find anything about this. If you can help me find a better way of doing this I would be very grateful

in Engine by (14 points)

1 Answer

0 votes

I think it is because your Area2D's collision shape is the same size as the solid KinematicBody2D collision shape. Try making the Area2D's collision shape slightly bigger than the solid region:
$CollisionShape2D.shape.radius = radius-1 $Hit/CollisionShape2D.shape.radius = radius
I hope this helps!

by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.