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)

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


    if isShrinking:
    if isGrowing:


func _shrink():

func _grow():

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 Frequently asked questions and 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 [email protected] with your username.