-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
shape='box' Add rigid body, why my rigid body is bigger than the actual object, I don't know what's wrong. #365
Comments
If it can't detect the shape, it will add 1x1x1 box. this.physics.add.existing(object, { shape: "mesh" }) But manually adding a box shape (like you did) is way better for performance. |
Yes, adding a box shape manually, does not take into account the rotation of the object. It just wraps a box as it is. |
Try to just manually switch width and height for now. |
Can you please upload the model? |
There are two models, one with the center point in the center and one with the center point not on the object. There is another problem if the center point is not the center point of the object, the resulting physical rigid body is at the center point instead of the center point of the object |
This works for me: import { PhysicsLoader, Project, Scene3D, THREE } from 'enable3d'
class MainScene extends Scene3D {
async preload() {
this.load.preload('obj1', '/assets/obj1.glb')
}
async create() {
this.warpSpeed()
this.camera.position.set(2, 2, 4)
this.physics.debug?.enable()
{
const obj1 = (await this.load.gltf('obj1')).scene
const box = new THREE.Box3()
const size = new THREE.Vector3()
const center = new THREE.Vector3()
box.setFromObject(obj1).getSize(size)
box.setFromObject(obj1).getCenter(center)
obj1.traverse(child => {
if (child.isMesh) {
child.material.metalness = 0
child.geometry.translate(-center.x, -center.y, -center.z)
}
})
this.add.existing(obj1)
this.physics.add.existing(obj1, {
shape: 'box',
width: size.x,
height: size.y,
depth: size.z
})
}
}
}
PhysicsLoader('/lib', () => new Project({ scenes: [MainScene] })) |
It doesn't work for me. Is the model you're testing mine? If |
Yes, your model. Yes. I tried it with setting a position and it worked. Just do it after the |
Okay、I tried using class MainScene extends Scene3D, rotation and center point in my demo and it worked. I put the demo in https://github.com/volcanoqq/enable3d-app, can you help me take a look at what's the problem cause。 |
Not sure. But you can manually adjust it. (See above) |
I want to make generic code with the performance because I am running this solution on mobile. Mesh is solving the problem right now but it is not the optimized way to achieve for this reason I am using 'Box' collider can you please help me how the manual width, height, depth solve my issue getBoundingSize: function(object){
|
Discussed in #364
Originally posted by volcanoqq September 26, 2023
And then I manually pass in width,height,depth, and it works.
I rotated the object in three.js before adding the rigid body, and then added the rigid body in the physical world in a box way, the rigid body did not apply the rotation, I don't know what went wrong
The text was updated successfully, but these errors were encountered: