I am scaling my canon body with a transform controller and it scales fine.
When I make mass 0, then I can see it scale perfectly.
and when mass is greater than 0, and the body is in the floor and I scale the physics body, it is in this state.
half of the body is under the floor which is also a physics body created by this:
const planeShape = new CANNON.Plane()
const planeBody = new CANNON.Body({ mass: 0 })
planeBody.addShape(planeShape)
planeBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2)
world.addBody(planeBody)
and for this physics body, first i am creating a box physics body and scaling it by transform controller
for scaling first i calculate the new value of halfExtents
it will have after scaling and update that by
function scalePhysicsBody(movingBody, x, y, z) {
let currentShape = movingBody.shapes[0]
movingBody.removeShape(currentShape)
if (myShape == 'SPHERE') {
currentShape.radius = Math.max(x, y, z)
movingBody.addShape(currentShape)
} else if (myShape == 'BOX') {
currentShape.halfExtents.set(x / 2, y / 2, z / 2)
movingBody.addShape(currentShape)
}
return movingBody
}
before scaling or doing anything, it need to be selected and moving body is the selected physics body which need to be scaled.
after i add shape to the body, do i need to call anything to update it ?
I am sorry if i am not providing much detail, i am just trying to give required detail so that it wont be clumsy.
I am afraid if i am able to articulate the situation, this is demo if it help !!
Do i need to add any other code?
This is scaling but mesh fall down the plane after scaling !!