Camera Direction Vector



I’m working on an FPS and I was wondering how to get the vector the camera is looking at.
I’d like to use the vector to spawn a projectile.

The code is already working, but only if I face a certain direction.
Since it’s a shooter, I want the projectiles to spawn in front of the player, no matter which direction they’re facing.

Any advice?,15359855


If you have entity that the camera component is attached to, you can use cameraEntity.forward where cameraEntity is the entity that the camera component is attached to.


I have tried that.
Both the cam and the player forward always return the same vector. Shouldn’t the vectors change if I rotate my viewport?

No matter player position or direction they’re looking at, in debug I always get:
camera force is [0, 0, -1]
force of player is[0, 0, -10]


Looks like a weird editor/data binding bug.

For whatever reason, is null on FirstPersonMovement script despite what is shown in the editor. This meant that a new camera is created in the first update of the script which is the one being rendered and controlled by the mouse.

I cleared the entry in the script in the editor and reassigned it the Camera in the scene again. After that, it works as expected.