Move the box with another when calculating on a neighboring neighboring grid in the file Three.js

I found many physical engines, but nothing that corresponded to my needs directly. I am trying to find an easy way to pull and pull out boxes, including collision detection, which will respect the next adjacent net kick when moving.

Some examples of use:

All fields except field 1 are movable.

Press or pull box 4 west:

  • Move field 3 west in a collision.
  • If box 3 and 4 cannot move west when field 3 falls into field 2.

Press 2, 3 or 4 North:

  • Must stop when it enters field 2 because field 1 does not move.

You cannot push or pull out 2 pillars with a box.

Maybe not the best question ... I could write such logic from scratch, but it would end up with rather complicated code :) and I wonder if anyone has allowed this before. Is there an easy way to implement this logic using the existing physics engine or the three.js plugin?

enter image description here

I hope that the question is well formulated so that anyone can understand it. Maybe easier. If you know the famous boulder shooting game.

Boulder dash 1 Both breeds can be moved in both directions.

enter image description here Unable to move stone.

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

0
source share
3 answers

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 based on the tile, when you are going to move the character, you first check the plate nearby , in the direction of movement, It can be a movable or occupied moving object (or a wall). If there is a moving object, then you check the next neighboring fragment. If it is passable, it means that the moving object is really moving. Otherwise, this moving object is not currently moving.

In a scenario other than slabs, you seem to check for collisions with the first field, and when that happens, you check for the next colliding field by adding a new column indicating the size of the first window in the direction of travel.

0
source

Thus, you want certain objects to be stationary at different points. You can do this with physi.js . Just increase the mass of the object so that it becomes so heavy in relation to other objects that it is motionless.

+2
source

I just answered a similar question here .

For this purpose you should use the bounding fields of type THREE.Box3 .

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

0
source

Source: https://habr.com/ru/post/1213133/


All Articles