Move collision component of child entity

Consider I am moving a screen with asteroids images and 3D sphere for in which moon has collision component. When player is moving along mouse move I am moving that screen in opposite direction. But collision component attached with moon remains to be in same previous position. How can I move child’s collision component along with its parent movement in play canvas ?

MouseControl.prototype.onMouseMove = function (e) {
    this.mousePos.set(e.x, e.y, 0);
};

MouseControl.prototype.update = function (dt) {
    if (this.pointerLocked) {

        this.camera.worldToScreen(this.entity.position, this.screenPos);
        this.screenPos.z = 0;
        this.directionToMouse.sub2(this.mousePos, this.screenPos);

        this.directionToMouse.y *= -1;
        var angle = Math.atan2(this.directionToMouse.x, this.directionToMouse.y) * pc.math.RAD_TO_DEG;
        var targetRotation = this.targetRotation.clone().setFromEulerAngles(90, 0, 90 - angle);
        var newRotation = this.newRotation.slerp(this.entity.getRotation(), targetRotation, 0.2);// slerp for smooth rotation
        this.entity.setRotation(newRotation);

        this.directionToMouse.normalize().scale(this.movementSpeed);

        this.entity.rigidbody.teleport(this.entity.getPosition().add(this.directionToMouse));

        this.movingScreen.translate(-this.directionToMouse.x * 1.5, -this.directionToMouse.y * 1.5, -this.directionToMouse.z * 1.5);


    }
}

Thank you

Static rigidbodies cannot be moved. You should make it kinematic.

1 Like