|Topic was automatically imported from the old Question2Answer platform.
I’ve already asked that on Discord as well, but got no response so I’ll repost it here:
I’m trying to solve a problem with Godot not detecting collisions. I’ve visualized it here:
I’m controlling a ball that hits tiles and certain tiles move one step (25px) when hit. They shouldn’t move when there’s another tile or the field border in that direction.
This sometimes seem to work (check the left tile hitting the border) and sometimes not (the on tile right from the working tile)
Now I’m wondering. I’m doing the whole collision detection and movement of the tile (I use move_and_collide to move the tile) inside _physics_process. Do I need to multiply the target vector for the tile with delta as well? I’d like to check, if the tile can move 25 pixels in the target direction and if so move it there directly.
I’ve tried to narrow down the problem and it gets rrrreally strange.
It happens when three tiles are directly next to each other. Then the middle tile can be pushed out of the field and after that all the other tiles as well.
See it in action:
I’m completely stumped.
Here’s the relevant code part:
var target_vector = normal * grid_size.x * -1
var disc_collision = tile.move_and_collide(target_vector, false, true, true)
if disc_collision == null:
Is the border always the same size, like a 10 x 10 grid?
If so, I wouldn’t do a collision detection, I’d clamp the values so the tile wouldn’t move outside of the border.
deaton64 | 2020-06-11 16:39
Yes, the grid is fixed and that’s a good idea for the border. But what about the other tiles? The collision doesn’t happen with them, too sometimes.
dploeger | 2020-06-11 16:48
I’m no expert, but I’d start by printing something everytime the ball colides, to make sure the collisions are being detected. If squares are not all of the same instance, make sure collision layers are set correctly.
Or maybe another approach is that you store the tile positions in an array [comment2-y]. just true or false to say if a square is occupide or not. The square would need to know it’s own position on the grid. Then if a tile gets hit, it knows which grid position it needs to move to and it can check if that space is empty by looking in the array. Then it can move or not move.
Obviously, you’d have to update the array.
This is a good example of using an array to store game pieces and checking if they are empty. Make a Match 3 game like Candy Crush Using Godot.
deaton64 | 2020-06-11 17:03
I already debugged through it and there really is no collision detected. The return of move_and_collide is null.
Yeah, the array solution came to my mind as well, but with Godot having a mature physics engine, I want to use that solution only as a last resort.
dploeger | 2020-06-11 17:09
Good luck. I hope you find a solution.
deaton64 | 2020-06-11 17:24
Thanks! I just sense that I might’ve missed something very important in this.
I don’t have much knowledge in physics engines.
dploeger | 2020-06-11 17:29