0

I want to position a box within a floor and 4 walls so the boxes movements would be within a constraint. This example shows a floor and backwall and works fine. However. I want to add left/right and front wall, so it can't exceed those bounds.

Adding in <PhyPlane color="lightblue" position={[0, 0, 10]} /> Which would add another plane near the user sends the physics boxes haywire. They get pushed out of the current camera view and don't just drop down like the original example.

But the boxes are within the 3 planes so it doesn't make sense why they're affected by the plane hitboxes.

How can I create a boundary plane box around a box so it won't move past that size. Like if the box is 10x10, if it hits the sides then it'd just interact like a normal physics object hitting a wall.

EDIT

Even with just 2 planes, <PhyPlane color="lightblue" position={[0, 0, 10]} /> modifying the existing backplane to be a frontplane with that code, the box object shoots off into nowhere.

I wonder if the issue is the rendering order of everything. So, ALL objects would render into the scene at exactly the same time. Both the box and the plane start at origin [0, 0, 0], then the plane moves to [0, 0, 10], which would push the box in that direction.

Can the plane be set not register any items until it reaches it's intended position?

Seems that, if I set the mass to be 0, or type not to be dynamic, the boxes wouldn't get initially pushed by the planes. Then I'd just need to set the type back to dynamic after the scene loaded up.

wanna_coder101
  • 508
  • 5
  • 19

2 Answers2

0

Fairly sure what I want is impossible. useCannon planes doesn't actually properly adhere to the set width/height. Say you set it to be [10,10], it'd actually still create an invisible plane for the width/height so objects get impacted far beyond the set w/h.

So, planes load in from the origin point and then move towards the position set. Since objects load from the origin point as well, the plane would push the object in the direction of travel. So, if you have a front and back plane, it'd push the object towards the front, but then the object can't get past the plane.

I tried using a box instead, setting the type to be static, would creates 4 walls surrounding the "ground" like I want. I believe boxes work because the load happens at the set position, not from origin, hence the collision pushing wouldn't happen.

However, when the impulse of an object is too high, the object just phases through the wall box instead of being stopped. This issue doesn't occur when using planes, but planes have the aforementioned issues...

wanna_coder101
  • 508
  • 5
  • 19
0

Use planes for the ground. Then use boxes for the sides. Boxes don't have weird physics effects like the plane does.

Note the depth MUST be greater than 10, if objects will have a high impulse. A low depth, like 0.5, will make the box flat as the plane, but objects can clip through it when their impulse is too high. Collisions don't even get detected because of how fast the object is moving. That is, when logging the onCollide event, nothing appears as the object clips through the wall.

Ie,

  // Using react fiber, drei helpers and useCannon
  // Create back wall, width/height 100
  <Box args={[100, 100, 10]} position={[0, 0, -10]}>
    <meshBasicMaterial />
  </Box>
wanna_coder101
  • 508
  • 5
  • 19