0 votes

After going through my code I found that this bit of code causes the Area2D to not detect any collision.

get_node("P2goal/P2 goal/CollisionShape2D").shape.extents.y = 54

I have also turned on visible Collision Shapes in the Debug and the shape does change correctly, does the extents property cause the CollisionShape not to register collisions as I don't get why this is causing the problem as when commented out it detects collisions normally.

Godot version 3.2.3
in Engine by (42 points)

This seems like a bug. I created a minimal reproduction project, but your line of code works fine for me (at least under Linux). What platform are you using? Does my minimal reproduction project work for you?

I tried your project and it seems to work, so I've changed it to kind of match what was going on in my game and I've recreated the issue it might be something to do with the process(delta) function but I'm not sure, project with the issue

I've figured out the cause of the issue if it is continuously trying to set the extents due to the _process(delta) function, the collision does not register as soon as it stops trying to change it is starts to work again. Not sure how to fix it though.

1 Answer

+1 vote
Best answer

Your code shouldn't be in the _process() function. It should be in _physics_process().

Edit: It looks like your code can be in _process(). If you try to set the collision extents every time _process() is run, then it doesn't work, but if you only try to set the collision extents sometimes then it does work:

func _process(delta):
    if Input.is_action_just_pressed("ui_accept"):
        pressed = !pressed
        var shape = get_node("P2goal/P2 goal/CollisionShape2D").shape
        if pressed:
            shape.extents.y = 54
        else:
            shape.extents.y = 32

That being said, I still feel like this behavior is a bug with Godot.

by (355 points)
edited by

Thanks, it worked, can I ask why as I thought you only use the _physics_process for things like kinematic movement

I've been doing some research and I haven't figured out why. I think that it has something to do with the order in which _process() and _physics_process() get run (see: Processing).

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.