Entity picking without physics on the rotated cube doesn't work

Hi ,
I have more than 100 cubes in my scene
I have to be able to select each one with Mouse
But adding rigidbody to this number of cubes and using raycast to select them , reduced the fps on lower devices
I want to use this project, to do this without rigidbody and physics

But when I rotate the cubes, this code again takes into account the cube that did not rotate

I even changed the code using this solution

BoundingBoxShape.prototype.initialize = function () {
    // Create the AABB and move the position of the box by the offset
    this.aabb = new pc.BoundingBox(this.entity.getPosition(), this.halfExtents);

BoundingBoxShape.prototype.postInitialize = function () {

    this.app.fire("shapepicker:add", this.entity, this.aabb);

BoundingBoxShape.prototype.postUpdate = function (dt) {

    this.aabb = this.entity.render.meshInstances[0].aabb;


But it does not work properly when rotating the cubes

pc.BoundingBox is an axis aligned bounding box so it’s not designed to be rotated. You would want pc.OrientedBox instead where you updated the world transform every frame: OrientedBox | PlayCanvas API Reference

So it be something like this (untested):

var transform = new pc.Mat4().setTRS(this.entity.getPosition(), this.entity.getRotation(), pc.Vec3.ONE);
var extents = this.entity.getLocalScale().clone().mulScalar(0.5);

this.box = new pc.OrientedBox(transform, extents);

// Then update it every frame
this.box.worldTransform.setTRS(this.entity.getPosition(), this.entity.getRotation(), pc.Vec3.ONE);

1 Like