Game Development Community

[SOLVED] How to get camera position of currently active camera?

by Keith G Wood · in Technical Issues · 08/19/2011 (8:01 am) · 2 replies

The problem I want to solve is to spawn a particle emitter at a fixed relative offset to the currently active camera position. To do this I need to read the postion of the camera (at least), and preferably the rotation as well (I could infer the rotation from the main player's rotation).

I am using the same default camera as comes with a new project. So it can be in either 1st or 3rd person view (tab key). I am aware that in a default new project I can use ALT-C to toggle between a player-tracking camera, and a camera that seems to be fixed at the player's original spawn location. (However I have disabled the ALT-C action, and dont use this fixed camera).

I have tried the following code, but it returns me the position of the camera located where the player was originally spawned...
%temp = ClientGroup.getObject(0);
%temp.player.client.camera.getTransform();

I have tried the following, but it appears to return me the location of the eyes of the player...
%temp = ClientGroup.getObject(0);
%temp.player.getEyeTransform();

This seems like such a fundamental item, I'm sure it must be possible. I just don't know how to get a handle on the currently active camera. I've tried searching forums but I can't seem find out how to do it.

Any help greatly appreciated.

#1
08/19/2011 (3:25 pm)
You might want to have a look at one of my older threads. The function I posted at the end can give you the position of the camera in third person. Let me know if that helps!
#2
08/19/2011 (11:51 pm)
Yes - that does exactly what I want - many thanks