Damn camera! Need help.
#1

When I try to set the camera to a certain point from where I was last facing, it turns to the right hand side of the screen instead of forwards.

How I store the coordinates in this variable:
pawn Код:
GetPlayerPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]);
GetPlayerFacingAngle(playerid, SavePos[playerid][picA]);
And here is the viewing:
pawn Код:
SetPlayerPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]+10); // so the player isn't visible.
SetPlayerFacingAngle(playerid, SavePos[playerid][picA]);
SetPlayerCameraPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]);
SetPlayerCameraLookAt(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]);
When viewed, it just turns to the right, do I need to set it to view the angle?
Halp!
Reply
#2

You're telling the camera to look at where you put it... To set the camera facing in the same direction as the player, you'd need to use GetXYInFrontOfPlayer() or similar to get a co-ordinate in front of the player, then set the camera to look at that.
Reply
#3

Alright, I've heard of such a function. How would I save that into a variable though? The same way I did for the positioning for the player?
Reply
#4

Okay I've tried this function but I don't know what to do, I've searched but it's confusing me. An example would be great. (Sorry for the double post).
Reply
#5

pawn Код:
SetPlayerPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]+10); // so the player isn't visible.

// SetPlayerFacingAngle() is unnecessary, this rotates the player in the world. We are dealing strictly with cameras.

SetPlayerCameraPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]);

#define DISTANCE 10.0
SetPlayerCameraLookAt(playerid, SavePos[playerid][picX] + DISTANCE * floatsin(-SavePos[playerid][picA], degrees), SavePos[playerid][picY] + DISTANCE * floatcos(-SavePos[playerid][picA], degrees), SavePos[playerid][picZ]);
This code calculates a new point that is DISTANCE away from the Camera's position, it makes use of the Camera facing angle you stored previously, and some laws of triangles. If you would like a more in-depth explanation let me know.

Changing DISTANCE to a larger value will change the Camera Look at location to a point that is farther away from the Camera.

Reply
#6

Thank you very much, works like a charm.
Reply
#7

Quote:
Originally Posted by samgreen
pawn Код:
SetPlayerPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]+10); // so the player isn't visible.

// SetPlayerFacingAngle() is unnecessary, this rotates the player in the world. We are dealing strictly with cameras.

SetPlayerCameraPos(playerid, SavePos[playerid][picX], SavePos[playerid][picY], SavePos[playerid][picZ]);

#define DISTANCE 10.0
SetPlayerCameraLookAt(playerid, SavePos[playerid][picX] + DISTANCE * floatsin(-SavePos[playerid][picA], degrees), SavePos[playerid][picY] + DISTANCE * floatcos(-SavePos[playerid][picA], degrees), SavePos[playerid][picZ]);
This code calculates a new point that is DISTANCE away from the Camera's position, it makes use of the Camera facing angle you stored previously, and some laws of triangles. If you would like a more in-depth explanation let me know.

Changing DISTANCE to a larger value will change the Camera Look at location to a point that is farther away from the Camera.

Sorry to bump, but I couldn't find a relevant existing up-to-date thread that anyone had replied in.

I can't seem to get this working:

SetPlayerCameraLookAt(playerid, 1474.6978 + DISTANCE * floatsin(90, 90), -1713.1594 + DISTANCE * floatcos(90, 90), 8.2497);

Bit of a newbie question, sorry.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)