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
Post a Comment