I am looking for a not too complicated solution for this:
When scenes collide in my 2D game (playing characters with other characters or objects) they move over or behind each other because of their Z value dependent on the Y value.
For this I have Z := -Y/10
But I don’t always want them to move over each other (pass each other); they should bump/collide when Y values of the scene object are between a minimum and maximum value, simulating a certain 3D “thickness” of the object. So Y should be a range I think. Or maybe there is a better way?
Only when Y value is smaller or larger than that the scenes should pass each other instead of 'bump."
I am experimenting with the code you provided yesterday
CanPass := (X > MaxX) or (X < MinX) or (Y > MaxY) or (Y < MinY) or (Z > MaxZ) or (Z < MinZ);
I started with the Y.
I get this error:
Also var Min.Y of WorldBoundingBox is Genericscalar but I have declared MinY Single;
What am I doing wrong here? And is it possible to use Y values from the Player Translation instead of its boundingbox?
MinY, MaxY: Single;
Z := -Y/10;
S := 1.6 - (0.0022 * Y);
Transform.Translation := Vector3(X, Y, Z);
Transform.Scale := Vector3(S, S, S);
if StatePlay.Location.PropsAmount > 0 then
for I := 1 to StatePlay.Location.PropsAmount do
MinY := StatePlay.Location.Props[I].Image.WorldBoundingBox.Min.Y + 50;
MaxY := StatePlay.Location.Props[I].Image.WorldBoundingBox.Max.Y - 20;
if StatePlay.Player.Transform.WorldBoundingBox.RectangleXY.Collides(StatePlay.Location.Props[I].Image.WorldBoundingBox.RectangleXY.Grow(-100, -100)) then
CanPass := (Y > MaxY) or (Y < MinY);
As for the message
Empty box 3D (Box.IsEmpty), cannot get minimum point
– it means you do
SomeBox is empty. Why this happens – you need to debug yourself, check
SomeBox.IsEmpty of various boxes. If you load some image, or load some 2D or 3D model to CastleScene that has some vertexes, then the box should not be empty.
As for a general answer: you can enlarge any dimension of a box or rectangle however you like, I see you already found ways to do so Since you do collision detection by manual checks, you have 100% control over the boxes/rectangles that you use. So in the end, it’s a matter of devising a proper algorithm to do this. I cannot help much based on this information, I can only say it is definitely possible. You can calculate the box/rectangle in any way necessary, you can make them smaller/larger along any axis as much as necessary.