Hi there, I’m trying to add collision element to generated mesh, mesh itself renders but collision appears as a plane PlayCanvas | HTML5 Game Engine
// Create a mesh with dynamic vertex buffer and static index buffer
const mesh = new pc.Mesh(app.graphicsDevice);
this.mesh = mesh;
mesh.clear(true, false);
this.updateMesh(mesh, true);
// create material
const material = new pc.StandardMaterial();
material.diffuseMap = this.app.assets.find('playcanvas-grey.png').resource;
material.shininess = 50;
material.metalness = 0.3;
material.useMetalness = true;
material.update();
// Create the mesh instance
const meshInstance = new pc.MeshInstance(mesh, material);
// Create the entity with render component using meshInstances
const entity = this.entity;
entity.addComponent("render", {
meshInstances: [meshInstance]
});
this.entity.addComponent('collision', {
type: 'mesh'
});
// We still have to create a model resource to create a runtime
// collision mesh
var node = new pc.GraphNode();
var collisionModel = new pc.Model();
collisionModel.graph = node;
collisionModel.meshInstances.push(meshInstance);
this.entity.collision.model = collisionModel;
this.entity.addComponent('rigidbody', {
friction: 0.5,
type: 'static'
});