Local Axis LookAt

Hi

I want to face my light shaft texture to the camera in local (or global ,i don’t know) x axis.
I tried many ways ,but does’n work properly



The first thing I would do is parent your object to another object that has no rotation, and have your script on that object. That will make things easier, as you now just need to copy the rotation of the camera, and don’t need a lot of crazy math to handle the initial rotation.

Also I think you want the rotation in Y. Something as simple as transform.eulerAngles = new Vector3(0f, Camera.main.transform.eulerAngles.y, 0f); should do in this case I think.

1 Like

I couldn’t find any solution yet

I want to create an look at script similar to this video from BF1:

my code in world space :

        transform.LookAt(new Vector3( startPos.x, target.position.y, target.position.z));

Look at to camera in local x axis (00:10)

have you tried Quaternion.LookRotation? I’m not for sure what your trying to achieve. the glare to face the camera? Ive used unity for years, just never made a account for forums. don’t judge my expierence by post count/join date.

I’m trying to face light shaft texture (with particle additive shader) always to the camera in local x axis. My main problem is local space look at . Ability to change rotation and fit position on the scene before game start
I have tested lots of ways and codes. all of those just works on world space. In this mode i can’t rotate shaft texture along light direction. Rotation will be reset to world after game start …

Not for sure which method it is exactly but it takes a param that you can set Space.Self? maybe its transform.Rotate, not for sure tho. just looked up the enum ( Unity - Scripting API: Space is the Space enum reference) never used it but it seems from the description it could keep it from reverting back to world on game start.

I’m not a beginner and know about these methods.

Just test and send me solution or sample code.

I have already tested more than 3-10 hour

I know its simple but my mathematic is not good specially in rotations.

yeh, rotations are my enemy to. ill try to proto type something out, and play a bit.

I cobbled together an example, see the attachment, is this the behaviour you’re after?

3022649–225850–angeledcameraface.unitypackage (7.28 KB)

It works fine

great thanks

A little issue:
The billboard rotates with camera rotation. It’s should be rotated according to camera movement (position) instead of rotation.

Then instead of using camera forward, use a vector from the camera to the billboard, and project that.

I think this should work, not tested

    void Update()
    {
        Vector3 direction = _cameraTransform.position - _transform.position;
        float dot = Vector3.Dot(direction, Vector3.up);
        bool orthogonal = ((dot == 1f) || (dot == -1f));
        if (orthogonal)
        {
            // ProjectOnPlane won't work if the camera forward is orthogonal
            // to the plane we're projecting on. In this case, just keep the
            // previous rotation.
            return;
        }

        Vector3 fwd = Vector3.ProjectOnPlane(
            direction, Vector3.up);

        Quaternion fwdRot = Quaternion.LookRotation(fwd, Vector3.up);

        _transform.localRotation = _initialRotation * fwdRot;
    }
1 Like

Yes it works fine. Now is same as BF1 style. Thank you…

1 Like