I want to know without a grid system what blocks are stacked on each other.
I have tried working with a point system. But that not working because the blocks can rotate. And it has influence on the sprite measurements.
So I tried raycasting.
But If I want to use the easy group method for checking it’s stuck on itself.
And if I raycast above it’s own. Then it only gives back the first hit. Or the last hit.
But with the last hit it also takes the first block if there are not other blocks on top. So that gives false positives.
What I would like is to have an raycast. Of a specific length. Then it returns the name of anything it hits in those rayscast.
The raycast now only gives the x and y back and then its also need extra a actions to know what it hits.
Other thing I was thinking.
If I can pick a object that is between the x of the block.
And then with the y of the stack order.
So then for every block it picks the 3 objectives above it.
But also with the pick nearest. You need to tell it can only pick between the lines of the x. And the y stack order. If there is nothing there it should not pick anything.
From the box perspective I want to know what other boxes are on top of it.
Its a free build stacking game where the blocks have interaction with each other.
This is the gamejam version what I made in defold.
If I understood correctly, you are trying to detect the blocks on top of a specific block.
Assuming your game is 2d,
I am thinking of using a sprite for the sole purpose of detecting blocks.
Create this detector sprite in the center of the block and increase by the height of block each iteration.
Every time you move it up, check if it collides with a block if it does, add one to a counter, if it doesn’t stop iterating.
This is what I mean:
Note: This won’t work if you want to detect all blocks above a block if there were gaps between them!
Your image isn’t showing. More context would help. Are the boxes physics objects? Do you need a list of the objects or a collision check between the objects. Like between boxes 1, 2 then 2,3 and so on.
You can look at the Javascript functions.
I think point is inside might be easier. You can use the the X, Y minus the object height times how many blocks away.
Another option would be a hitbox object used for testing.
IDK if it would be easier to test things as boxes drop and collide or scan the stack from the bottom up each time.
It might even be useful to use object variables for things like weight, maxWeight or maxWeight per block type. IDK just brainstorming.
I think there is a way to create a new function that gives a list of objectives back it hit. because i see it natively is creating a list of objects hit.
So i need to dive into it because this is new for me.
Or if someone with more experience see this and thing. That would be workable for me would be great
One issue with raycast is that it could miss a block that is hanging more than halfway off the stack, to avoid this you would need at least two rays (sufficient if the blocks are always wide enough).
Personally, I would go for the invisible hitbox solution anyway, which seems easier in terms of object-picking. There’s many ways to go about it, here’s one that just popped in my head:
Link hitbox to block that is being checked
As the hitbox moves up and collides with blocks, add their weight to some variable like totalWeight.
When the hitbox is done colliding, compare the totalWeight to the linked block’s strength
You might want to use the object picking tools extension, which provides an action to un-pick objects (I feel like this should be integrated into GD, has solved many problems for me…)