0 votes

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:

enter image description 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 moveandcollide to move the tile) inside physicsprocess. 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.

Thanks!

Kind regards
Dennis

Update

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:

enter image description here

enter image description here

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:
  tile.translate(target_vector)
asked Jun 11 in Engine by dploeger (12 points)
edited Jun 11 by dploeger

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.

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.

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 [x][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.

I already debugged through it and there really is no collision detected. The return of moveandcollide 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.

Thanks anyway.

Good luck. I hope you find a solution.

Thanks! I just sense that I might've missed something very important in this.

I don't have much knowledge in physics engines.

1 Answer

0 votes

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. 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.

answered Jun 12 by myshopee (14 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 How to use this Q&A? before posting your first questions.