unity3d - How to get the ray that faces Camera? -


two days i'm trying proper ray camera.

i have script simulate recoil of gun rotates camera of built-in firstpersoncharacter of unity. rotates simple cam.transform.rotate(x, 0, 0); can't manage ray there, cam.transform.forward horizontal if camera not rotated , cam.viewporttoworldpoint doesn't work neither.

do guys have idea how work ?

when rotate camera cam.transform.rotate(0,y,0) rotate camera around y-axis. means camera remains horizontal, rotates left , right (probably not best way simulate recoil).

to rotate camera vertically in way resembling recoil, should lerp camera.transform.forward camera.transform.up coefficient, 0.5f or something.

update, example code:

    if (input.getkeydown(keycode.space))     {         var direction = vector3.lerp(camera.main.transform.forward, camera.main.transform.up, 0.1f);         camera.main.transform.lookat(camera.main.transform.position + direction);         var ray = new ray(camera.main.transform.position, direction);     } } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -