Im trying to create spheres with a collider and rigidbody, im using TS, here is how im trying to call the system:
if (app.systems.rigidbody) {
app.systems.rigidbody.onLibraryLoaded();
console.log('Ammo system activated');
}
And here is how Im trying to call it from the spheres:
// Create the sphere entity for the pointer
const sphere = new Entity('sphere');
sphere.addComponent('render', {
type: 'sphere',
material: materialSphere,
collider: {
type: 'sphere',
radius: 0.125
},
rigidbody: {
type: 'dynamic'
}
Hi @luis.rioja and welcome!
In your code you add a render component, but you need to add a collision and rigidbody outside of that.
Here are the links to references on how to do this:
Thanks for the response and the welcome!!
I already tried using this documentation but is not working. Here is the function and below what the console shows me.
// Create the sphere entity for the pointer
const sphere = new Entity('sphere');
sphere.addComponent('render', {
type: 'sphere',
material: materialSphere,
collider: {
type: 'sphere',
radius: 0.125
},
rigidbody: {
type: 'dynamic'
}
});
// Set the scale of the sphere to adjust its size
sphere.setLocalScale(0.25, 0.25, 0.25);
// Set the position of the sphere to the mouse position
sphere.setPosition(1, 0, 1);
this.app.root.addChild(sphere);
const entityRB = new pc.Entity();
entityRB.addComponent('collision', {
type: 'sphere'
});
entityRB.addComponent('rigidbody', {
type: 'dynamic'
});
console.log(entityRB.rigidbody);
// Add the entityRB as a child of the sphere
sphere.addChild(entityRB);
undefined
When I tried to read some data like the mass it gives me an error like this one.
console.log(entityRB.rigidbody.mass);
Console shows:
Uncaught TypeError: Cannot read properties of undefined (reading 'mass')
Hi,
I tested your code and the main error I found was for creating your sphere entity. You used
new Entity() when you need to use new pc.Entity().
Once that was fixed, it gave me a mass reading of 1.
It gaves me the exact same error, I also tried to implement the rigidbody and the collider into the sphere directly.
Can you please share your editor link?
Its a modified version of the modelviewer project, is not hosted on the online editor :((