Hide entities between third camera and player


I am working on a game and need an advice for a good game experience.

Can someone give me an advice on how to hide in this video sequence the street lamp which appears during camera rotation between the third camera view and the player located with the punk character ?

May be something around raycasting ?


Yes you can use raycasting. You can cast a ray from the camera to the player using the raycastAll method which returns an array of entites that were hit by the raycast. You can then hide their models using entity.model.hide().

1 Like


I tried something but the results are strange.

var from = this.entity.camera.screenToWorld(window.innerWidth*0.5, window.innerHeight*0.5, this.entity.camera.farClip);
        // to player position
        var to = this.app.root.findByName('Player').getPosition();

        var result = this.app.systems.rigidbody.raycastAll(from, to);
        // If there was a hit, store the entity
        if (result) {

The project is here : https://playcanvas.com/project/736977/overview/lockdown

Try to replace farClip with nearClip