How to maintain a constant depth

Options

I have 3d object similar to the potato filter which has a head binding with eye and mouth.
Currently as in the case of the potato filter it grows the closer you get to the camera.

Can someone please tell me how to fix the size so it tracks left and right but does not grow in size. Thanks

Answers

  • Max
    Max Posts: 26 🔥
    Options

    You could set its position in an update event and overwrite it on every frame!

    The following script first gets the object parent's world position,
    converts it to screen space,
    converts it back to world space at a custom distance (100cm away from the camera in this case),
    and then applies it to the object:

    //@input SceneObject object
    //@input Component.Camera cam
    
    var distance = 100;
    
    function overwritePosition(){
        var pos = script.object.getParent().getTransform().getWorldPosition();
        var screenPosition = script.cam.worldSpaceToScreenSpace(pos);
        var worldPosition = script.cam.screenSpaceToWorldSpace(screenPosition, distance);
        script.object.getTransform().setWorldPosition(worldPosition);
    }
    var overwritePositionEvent = script.createEvent('UpdateEvent');
    overwritePositionEvent.bind(overwritePosition);
    
  • Chris Hughes
    Chris Hughes Posts: 3
    edited September 2022 #3
    Options

    Hi Max.
    Thanks for this. By doing this it stays the same size but I want to enable movement left and right only.
    Thanks for your help