Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect parent position, rotation[, scale?] #311

Open
mattblackdev opened this issue Dec 16, 2021 · 2 comments
Open

Respect parent position, rotation[, scale?] #311

mattblackdev opened this issue Dec 16, 2021 · 2 comments

Comments

@mattblackdev
Copy link

Sometimes you want to do this:

function Thing({ position, rotation }) {
  const [ref] = useBox(() => ({ position, rotation }));
  return (
    <Box ref={ref} />
  );
}

function CoolThing({ position, rotation }) {
  return (
    <group position={position} rotation={rotation}>
      <Thing position={offset1} />
      <Thing position={offset2} />
      <Thing />
      <Thing rotation={offsetRot} />
    </group>
  );
}

But then you learn that the physics world has no consideration of the scene hierarchy.

And you might even try to do this:

<Box onUpdate={self => {
  const v = new Vector3()
  self.getWorldPosition(v)
  api.position.copy(v)
}} />

But in the end you learn that this is a harder problem to solve indeed...

So you create a repro of the issue:
https://codesandbox.io/s/use-cannon-not-respecting-parent-rchms?file=/src/App.tsx

And you go back to manually managing world positions:

function CoolThing({ position, rotation }) {
  return (
    <>
      <Thing position={add(position, offset1)} rotation={rotation} />
      <Thing position={add(position, offset2)} rotation={rotation} />
      <Thing position={position} rotation={rotation} />
      <Thing position={position} rotation={add(rotation, offsetRot)} />
    </>
  );
}
@bjornstar
Copy link
Member

I don't really understand the problem you are reporting.

You have 4 different physics objects inside of a group, but the group has no physics representation.

What is it supposed to be doing? Is it affecting the positions and rotations of the 4 physics bodies?

This looks to me like a single CompoundBody with 4 shapes. Have you tried using that?

@mattblackdev
Copy link
Author

I see what you mean. I implemented parts of structures (walls, floors, etc.) and interior objects as separate components that could be composed interchangeably.

When it came time to position different compositions I tried putting them inside groups to only manage one world position per building. Problem was the groups' position didn't affect the children's colliders, only their meshes.

I get the compound body approach but it doesn't seem ideal for composing components that have their own colliders.

Thanks for giving this some thought. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants