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

有些话、适合烂在心里 提交于 2019-12-13 02:02:52

问题


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?

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

Possible to move both rocks in both directions.

Impossible to move a rock.

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


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/28449382/move-a-box-with-another-on-colission-respecting-the-next-neighboring-mesh-in-thr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!