在Threes.js中移动一个与Boxs相连的盒子,尊重下一个相邻的网格 [英] Move a Box with another on colission respecting the next neighboring mesh in Three.js

查看:111
本文介绍了在Threes.js中移动一个与Boxs相连的盒子,尊重下一个相邻的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里发现了很多物理引擎,但是没有任何东西可以直接满足我的需求。
我试图找到一种推拉盒子的简单方法,包括碰撞检测,该检测在移动时尊重下一个相邻的网格物体。

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.

一些用例可以理解:

除框1外的所有框都是可移动的。

All boxes except box 1 are moveable.

将方格4推入或拉出向西:

Push or Pull box 4 to west:


  • 在碰撞时应将方格3向西移动。

  • 当第3个框碰到第2个框时,应使第3个框和第4个框不能向西移动。

将2、3或4推向北:


  • 当其碰到方框2时应停止,因为方框1不可移动。

应该不可能用盒子推或拉两个碰撞的盒子。

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

也许这不是最好的问题...我可以从头开始编写这样的逻辑,但这将以相当复杂的代码结尾:),我想知道是否没有人解决过类似的问题。
是否存在使用现有的物理引擎或three.js插件实现这种逻辑的简便方法?

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.

在我看来,移动2个碰撞的岩石/多维数据集,但不移动3个。

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

推荐答案

非常简单,与物理和几何有关而不是与物理有关……如果我了解您的简化世界。

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

在boulderdash(或sokoban)的情况下,动作是基于平铺的,当您要移动角色时,首先在运动方向上检查相邻磁贴。它可以是步行的,也可以被可移动的物体(或墙壁)占据。如果有可移动的对象,请检查下一个相邻图块。如果它是可行走的,则表示它确实是可移动的。否则,该可移动对象当前无法移动。

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.

这篇关于在Threes.js中移动一个与Boxs相连的盒子,尊重下一个相邻的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆