Move a Box with another on colission respecting the next neighboring mesh in Three.js
Asked Answered
J

3

1

Found a lot of physic engines out there but nothing that fit my needs directly. I try to to find a simple way to push and pull boxes including collision detection which respects the next neighboring mesh hit while moving.

Some use cases to understand:

All boxes except box 1 are moveable.

Push or Pull box 4 to west:

  • Should move box 3 to west on collision.
  • Should make box 3 and 4 not able to move west when box 3 hits box 2.

Push 2, 3 or 4 to north:

  • Should stop when it hits box 2, because box 1 is not movable.

it should not possible to push or pull 2 colliding boxes with a box.

Maybe not the best question... I could write such a logic from scratch but this would end in fairly complex code :) and I wonder if nobody solved something like that before. Does there exist an easy way to implement such a logic using an existing physic engine or a three.js plugin?

enter image description here

Hope the question is formulated well enough so that anyone can understand it. Maybe easier If you know the famous boulder dash game.

Boulder Dash 1 Possible to move both rocks in both directions.

enter image description here Impossible to move a rock.

In my case it should be possible to move 2 colliding rocks/cubes but not 3.

Jasun answered 11/2, 2015 at 8:8 Comment(0)
E
1

Pretty simple, it's more about geometry and logic than physics... if I understand your simplified world.

In the case of boulderdash (or also sokoban), where the movement is tiled-based, when you are about to move the character you first check the adjacent tile, in the direction of the movement. It could be walkable or occupied by a movable object (or also a wall). If there's a movable object, then you check the next adjacent tile. If it's walkable then means the movable object it's indeed movable. Otherwise, that movable object is currently not movable.

In a non-tiled scenario like yours seems, you check for collision with a first box and, when this happens, you check the presence of a next colliding box, adding a new colision point the size of the first box, in the direction of the movement.

Eshman answered 17/4, 2015 at 0:19 Comment(1)
@ruberto-valdunciel Pretty simple ^^. Thanks . I already realised this approach wich results in a new question at #28753261. Anyway I will accept your answer.Jasun
S
3

So basically you want to make certain objects immovable at various points. You can do this with physi.js. Just increase the mass of the object so it becomes so heavy relative to the other objects that it is immovable.

Supercilious answered 11/2, 2015 at 15:14 Comment(2)
So far this is the besteht answer. But my app is move based and i think that implement a physic engine is much too complicated for that use case. Instead I have written my own code to detect next neighbor meshes.Jasun
In your question you clearly stated you were looking at solutions involving physics engines but now it seems you're excluding these solutions. So my answer fits the question. Pls accept it if you agree. By the way I found physics engines to actually result in simple clean code. Better than hundreds of lines of hand-rolled partial implementations. If others are going to look at or support your code, that matters.Supercilious
E
1

I just answered a similar question here.

You should use bounding boxes of type THREE.Box3 for this purpose.

You should definitely check this example out. I think it will be very useful for you.

Eagleeyed answered 11/2, 2015 at 15:6 Comment(0)
E
1

Pretty simple, it's more about geometry and logic than physics... if I understand your simplified world.

In the case of boulderdash (or also sokoban), where the movement is tiled-based, when you are about to move the character you first check the adjacent tile, in the direction of the movement. It could be walkable or occupied by a movable object (or also a wall). If there's a movable object, then you check the next adjacent tile. If it's walkable then means the movable object it's indeed movable. Otherwise, that movable object is currently not movable.

In a non-tiled scenario like yours seems, you check for collision with a first box and, when this happens, you check the presence of a next colliding box, adding a new colision point the size of the first box, in the direction of the movement.

Eshman answered 17/4, 2015 at 0:19 Comment(1)
@ruberto-valdunciel Pretty simple ^^. Thanks . I already realised this approach wich results in a new question at #28753261. Anyway I will accept your answer.Jasun

© 2022 - 2024 — McMap. All rights reserved.