0 votes

Hi. I want to detect collisions between a drawn circle using the draw_arc command with my scene, consisting of polygon2Ds. I have this code:

#Todo: How to attach collision shape to a draw primitive

extends Node2D

# Called when the node enters the scene tree for the first time.
func _ready():
    randomize()

func _draw():
    var smaller: int = -1
    if get_viewport().size.x <= get_viewport().size.y:
        smaller = get_viewport().size.x
    else:
        smaller = get_viewport().size.y
    var radius = randi() % (smaller / 2)
    var x = randi() % ((get_viewport().size.x as int)-radius)
    var y = randi() % ((get_viewport().size.y as int)-radius)
    var shape = CircleShape2D.new()
    shape.radius = radius
    var coll_shape = CollisionShape2D.new()
    coll_shape.set_shape(shape)
    draw_arc(Vector2(x,y), radius, 0, 360, 1000, Color(1.0,0,0,1.0), 1)

Is it possible to somehow make a drawn primitive have a collisionshape? The script is associated with the root node.

in Engine by (14 points)

Isn't this the same question as:

https://godotengine.org/qa/61416/how-add-collisionshape-shape-circleshape2d-draw-primitive

If so, you'll get more assistance by keeping everything in a single question...

Yeah it is the same.

I thought i did not post the thread as it did not show up in my questions. It just took some time to get approved.

Appologies for the duplication.

Please log in or register to answer this question.

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.