SA-MP Forums Archive
Camera Movement.. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Camera Movement.. (/showthread.php?tid=617960)



Camera Movement.. - vassilis - 29.09.2016

I am trying to make a camera movement.. I want it to change camera positions every specific time.
I had added some beta client messages like CAM1, CAM2, etc..
When i am using it it prints:
Код:
CAM1
CAM2
CAM3
CAM4
CAM5
Around 1 second..

So what really happens is that it ignores every case and is going straight a the 5th.
PHP код:
                        else 
                        {
                                
                                
ShowRegisterScreen(playerid);
                                
pinfo[playerid][Banned] = 0;
                                
CameraMovement[playerid] = 1;
                                
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"10000"i"playerid);
                        } 
PHP код:
                            function ConnectionCameraMovement(playerid)
                {
                    
TogglePlayerSpectating(playerid1);
                    switch(
CameraMovement[playerid])
                    {
                        case 
1:
                        {
                            
SendClientMessage(playerid, -1"CAM1");
                            
InterpolateCameraPos(playerid1977.940917, -1753.39416515.7100481683.647583, -1725.14978015.52067613000);
                            
InterpolateCameraLookAt(playerid1972.946899, -1753.48962415.4856461688.493530, -1726.38122515.5003652000);
                            
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"15000false"i"playerid);
                            
CameraMovement[playerid] = 2;    
                        }                
                        case 
2:
                        {
                            
SendClientMessage(playerid, -1"CAM2");
                            
InterpolateCameraPos(playerid905.286132, -1403.62597615.1548441353.317626, -1404.65539515.98913610000);
                            
InterpolateCameraLookAt(playerid910.276306, -1403.32617115.0623101349.223632, -1401.78662115.8922682000);
                            
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"12000false"i"playerid);
                            
CameraMovement[playerid] = 3;
                        }
                        case 
3:
                        {
                            
SendClientMessage(playerid, -1"CAM3");
                            
InterpolateCameraPos(playerid1584.561767, -1731.50170814.4981491334.697753, -1722.91162115.10458710000);
                            
InterpolateCameraLookAt(playerid1579.567993, -1731.75073214.4778371338.359619, -1726.31591715.0587542000);    
                            
KillTimer(ConnectionCamera[playerid]);
                            
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"12000false"i"playerid);
                            
CameraMovement[playerid] = 4;
                        }    
                        case 
4:
                        {
                            
SendClientMessage(playerid, -1"CAM4");
                            
InterpolateCameraPos(playerid165.131668, -1885.5817871.454522636.477600, -1918.9556885.68883410000);
                            
InterpolateCameraLookAt(playerid170.110122, -1885.1679681.663836631.661071, -1917.6795655.2734292000);
                            
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"12000false"i"playerid);
                            
CameraMovement[playerid] = 5;
                        }    
                        case 
5:
                        {
                            
SendClientMessage(playerid, -1"CAM5");
                            
InterpolateCameraPos(playerid1828.909790, -1602.99597113.4857911857.642089, -1431.32031216.74403310000);
                            
InterpolateCameraLookAt(playerid1825.495117, -1599.40734814.1651931852.764038, -1432.40222116.5578802000);
                            
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement"12000false"i"playerid);
                            
CameraMovement[playerid] = 1;
                        }
                    }
                    return 
1;
                } 



Re: Camera Movement.. - SickAttack - 29.09.2016

You could rewrite your code to something like below:
pawn Код:
// Initialize

TogglePlayerSpectating(playerid, true);

CameraMovement[playerid] = 0;

KillTimer(ConnectionCamera[playerid]);
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement", 1000, true, "i", playerid);

// Function

forward ConnectionCameraMovement(playerid);
public ConnectionCameraMovement(playerid)
{
    switch(CameraMovement[playerid])
    {
        case 0:
        {
            InterpolateCameraPos(playerid, 1977.940917, -1753.394165, 15.710048, 1683.647583, -1725.149780, 15.520676, 13000);
            InterpolateCameraLookAt(playerid, 1972.946899, -1753.489624, 15.485646, 1688.493530, -1726.381225, 15.500365, 2000);

            CameraMovement[playerid] ++;
        }
        case 1:
        {
            InterpolateCameraPos(playerid, 905.286132, -1403.625976, 15.154844, 1353.317626, -1404.655395, 15.989136, 10000);
            InterpolateCameraLookAt(playerid, 910.276306, -1403.326171, 15.062310, 1349.223632, -1401.786621, 15.892268, 2000);

            CameraMovement[playerid] ++;
        }
        case 2:
        {
            InterpolateCameraPos(playerid, 1584.561767, -1731.501708, 14.498149, 1334.697753, -1722.911621, 15.104587, 10000);
            InterpolateCameraLookAt(playerid, 1579.567993, -1731.750732, 14.477837, 1338.359619, -1726.315917, 15.058754, 2000);

            CameraMovement[playerid] ++;
        }
        case 3:
        {
            InterpolateCameraPos(playerid, 165.131668, -1885.581787, 1.454522, 636.477600, -1918.955688, 5.688834, 10000);
            InterpolateCameraLookAt(playerid, 170.110122, -1885.167968, 1.663836, 631.661071, -1917.679565, 5.273429, 2000);

            CameraMovement[playerid] ++;
        }
        default:
        {
            InterpolateCameraPos(playerid, 1828.909790, -1602.995971, 13.485791, 1857.642089, -1431.320312, 16.744033, 10000);
            InterpolateCameraLookAt(playerid, 1825.495117, -1599.407348, 14.165193, 1852.764038, -1432.402221, 16.557880, 2000);

            CameraMovement[playerid] = 0;
        }
    }
    return 1;
}
Just remember to kill the timer when you're done with it.

Also, note that interpolate functions aren't fully accurate in terms of working. They do not always move your camera. You could replace its usage for SetPlayerCameraLookAt, using CAMERA_MOVE in the cut parameter, but you'd be sacrificing the control over time.


Re: Camera Movement.. - iLearner - 29.09.2016

You could try using break; at the end of every case... Not sure I pawn but it helped me in c++ / java.


Re: Camera Movement.. - SickAttack - 29.09.2016

Quote:
Originally Posted by iLearner
Посмотреть сообщение
You could try using break; at the end of every case... Not sure I pawn but it helped me in c++ / java.
It isn't required in PAWN.


Re: Camera Movement.. - Threshold - 29.09.2016

You realise your code would just result in the camera being changed every second and then restarting again, right?


Re: Camera Movement.. - vassilis - 29.09.2016

Basically, i was trying to understand how interpolated cameras are read by compiler. I thought compiler will wait the seconds the camera is moving and then use the timer. That's why it didn't work. Thank you all!


Re: Camera Movement.. - vassilis - 30.09.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You could rewrite your code to something like below:
pawn Код:
// Initialize

TogglePlayerSpectating(playerid, true);

CameraMovement[playerid] = 0;

KillTimer(ConnectionCamera[playerid]);
ConnectionCamera[playerid] = SetTimerEx("ConnectionCameraMovement", 1000, true, "i", playerid);

// Function

forward ConnectionCameraMovement(playerid);
public ConnectionCameraMovement(playerid)
{
    switch(CameraMovement[playerid])
    {
        case 0:
        {
            InterpolateCameraPos(playerid, 1977.940917, -1753.394165, 15.710048, 1683.647583, -1725.149780, 15.520676, 13000);
            InterpolateCameraLookAt(playerid, 1972.946899, -1753.489624, 15.485646, 1688.493530, -1726.381225, 15.500365, 2000);

            CameraMovement[playerid] ++;
        }
        case 1:
        {
            InterpolateCameraPos(playerid, 905.286132, -1403.625976, 15.154844, 1353.317626, -1404.655395, 15.989136, 10000);
            InterpolateCameraLookAt(playerid, 910.276306, -1403.326171, 15.062310, 1349.223632, -1401.786621, 15.892268, 2000);

            CameraMovement[playerid] ++;
        }
        case 2:
        {
            InterpolateCameraPos(playerid, 1584.561767, -1731.501708, 14.498149, 1334.697753, -1722.911621, 15.104587, 10000);
            InterpolateCameraLookAt(playerid, 1579.567993, -1731.750732, 14.477837, 1338.359619, -1726.315917, 15.058754, 2000);

            CameraMovement[playerid] ++;
        }
        case 3:
        {
            InterpolateCameraPos(playerid, 165.131668, -1885.581787, 1.454522, 636.477600, -1918.955688, 5.688834, 10000);
            InterpolateCameraLookAt(playerid, 170.110122, -1885.167968, 1.663836, 631.661071, -1917.679565, 5.273429, 2000);

            CameraMovement[playerid] ++;
        }
        default:
        {
            InterpolateCameraPos(playerid, 1828.909790, -1602.995971, 13.485791, 1857.642089, -1431.320312, 16.744033, 10000);
            InterpolateCameraLookAt(playerid, 1825.495117, -1599.407348, 14.165193, 1852.764038, -1432.402221, 16.557880, 2000);

            CameraMovement[playerid] = 0;
        }
    }
    return 1;
}
Just remember to kill the timer when you're done with it.

Also, note that interpolate functions aren't fully accurate in terms of working. They do not always move your camera. You could replace its usage for SetPlayerCameraLookAt, using CAMERA_MOVE in the cut parameter, but you'd be sacrificing the control over time.
Sorry for double post but it didn't really work out like that.. it just shows only one moving camera again.. it is just a different one this time.

EDIT: I found another way to solve it.


Re: Camera Movement.. - SickAttack - 30.09.2016

Quote:
Originally Posted by vassilis
Посмотреть сообщение
Sorry for double post but it didn't really work out like that.. it just shows only one moving camera again.. it is just a different one this time.
You need to change the interval of the timer.