I can't move on to my "Else" statement. what am I missing?
Asked Answered
V

1

0

I'm able to use my code to push blocks, and it was working fine, but I wanted to make sure I couldn't push a block into a wall, or another block. to do that, I added some code...

`func _process(delta):

for body in area_right.get_overlapping_bodies():
    if body.is_in_group("Player"):
        if(hero.get_collision_layer() == 1):
            arrow_left.show()
            if  Input.is_action_just_pressed("Push"):
                move_left()

func move_left() -> void:
for body in area_left.get_overlapping_bodies():
if(body.get_collision_layer() == 1):
print("Nope")
else:
print("works")
block.position.x -= 1 * 128`

everything from "for body in area_left" to "print("works")" is what I added. everything works, up to printing "Nope". but now, a block in front of me or not, I can't push to the left, or even print the word "works". I'm still pretty new to Godot, and coding, so I'm sure I'm missing something obvious here.

Valadez answered 18/2, 2024 at 4:46 Comment(0)
P
0

Well, there are many problems.
In order for things to happen BOTH area left and area right have to have colliding objects, which is a very rare ocurrence.
Also you are running in _process, it should be in physics process instead.
You are checking for layers for some reason when it's already in a group AND has collided. Areas have layers that they detect or ignore.

So, set up your layers, put objects in different layers.
Clean up your code, remove what's redundant or start over.
And try using signals or solving the problem a different way. Checking for collisions every frame is not very efficient.

Peregrinate answered 18/2, 2024 at 7:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.