[HELP] Moving a camera on a 2D axis
#1

Yo.
I have a small drama:
I'm scripting currently a "guided missile" which starts in the sky and travels down to the ground.

It's launched > Heads @ a set location > Detonates on arrival.

This was all good, no bugs or anything.
The next step was to make the missile CONTROLLABLE, which has been quite a task lmao.

For camera movement, I'm using nCamera by Norn.

I'll post all the coding i've done so far to try and make this work


OnPlayerCommandText()
pawn Код:
if(strcmp(cmd, "/atgm", true) == 0)
    {
        if(PlayerInfo[playerid][pAdmin] == 9999)
        {
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "You are now controlling an atgm");
            ControllingMissile[playerid] = 1;
            HasMissileMoved[playerid] = 0;
            GetPlayerPos(playerid, MissileTarget[playerid][0], MissileTarget[playerid][1], MissileTarget[playerid][2]);
            ControlMissile(playerid);
        }
    }
ControlMissle() ~Rob
pawn Код:
public ControlMissile(playerid)
{
    TogglePlayerControllable(playerid, 0);
    HasMissileMoved[playerid] = 0;
    GetPlayerPos(playerid, MissileTarget[playerid][0], MissileTarget[playerid][1], MissileTarget[playerid][2]);
    ControllingMissile[playerid] = 1;
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    SetCameraPosForPlayer(playerid, X, Y, Z + 500, MissileTarget[playerid][0], MissileTarget[playerid][1], MissileTarget[playerid][2], 100, false, false);
   
}
MoveMissle() ~Rob
pawn Код:
public MoveMissile(playerid)
{
    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);
    SetPlayerCheckpoint(playerid, MissileTarget[playerid][0], MissileTarget[playerid][1], MissileTarget[playerid][2], 50);
    if(ud > 0)//down
    {
            new Float:LocX, Float:LocY, Float:LocZ;
            new Float:EndX, Float:EndY, Float:EndZ;
            new Float:VX, Float:VY, Float:VZ;
            GetPlayerCameraFrontVector(playerid, VX, VY, VZ);
            if(HasMissileMoved[playerid] = 0)
            {
                GetPlayerPos(playerid, EndX, EndY, EndZ);
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                HasMissileMoved[playerid] = 1;
            }
            else if(HasMissileMoved[playerid] = 1)
            {
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                EndX = MissileTarget[playerid][0];
                EndY = MissileTarget[playerid][1];
                EndZ = MissileTarget[playerid][2];
            }
            //LocX = LocX;
            //LocY = LocY - ATGM_MOVE_DISTANCE;
            //LocZ = LocZ;
            EndX = EndX;
            EndY = EndY - ATGM_MOVE_DISTANCE;
            EndZ = EndZ;
            LocX = LocX;
            LocY = LocY - ATGM_MOVE_DISTANCE;
            LocZ = LocZ;
            DestroyCameraForPlayer(playerid);
            SetCameraPosForPlayer(playerid, LocX, LocY, LocZ - ATGM_Z_FIX, EndX, EndY, EndZ, 100, false, false);
            MissileTarget[playerid][0] = EndX;
            MissileTarget[playerid][1] = EndY;
            MissileTarget[playerid][2] = EndZ;
            return 1;
           
    }
    else if(ud < 0)//up
    {
            new Float:LocX, Float:LocY, Float:LocZ;
            new Float:EndX, Float:EndY, Float:EndZ;
            if(HasMissileMoved[playerid] = 0)
            {
                GetPlayerPos(playerid, EndX, EndY, EndZ);
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                HasMissileMoved[playerid] = 1;
            }
            else if(HasMissileMoved[playerid] = 1)
            {
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                EndX = MissileTarget[playerid][0];
                EndY = MissileTarget[playerid][1];
                EndZ = MissileTarget[playerid][2];
            }
            LocX = LocX;
            LocY = LocY + ATGM_MOVE_DISTANCE;
            LocZ = LocZ;
            EndX = EndX;
            EndY = EndY + ATGM_MOVE_DISTANCE;
            EndZ = EndZ;
            DestroyCameraForPlayer(playerid);
            SetCameraPosForPlayer(playerid, LocX, LocY, LocZ - ATGM_Z_FIX, EndX, EndY, EndZ, 100, false, false);
            MissileTarget[playerid][0] = EndX;
            MissileTarget[playerid][1] = EndY;
            MissileTarget[playerid][2] = EndZ;
            return 1;
    }

    if(lr > 0)//right
    {
   
        new Float:LocX, Float:LocY, Float:LocZ;
            new Float:EndX, Float:EndY, Float:EndZ;
            if(HasMissileMoved[playerid] = 0)
            {
                GetPlayerPos(playerid, EndX, EndY, EndZ);
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                HasMissileMoved[playerid] = 1;
            }
            else if(HasMissileMoved[playerid] = 1)
            {
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                EndX = MissileTarget[playerid][0];
                EndY = MissileTarget[playerid][1];
                EndZ = MissileTarget[playerid][2];
            }
            LocX = LocX + ATGM_MOVE_DISTANCE ;
            LocY = LocY ;
            LocZ = LocZ;
            EndX = EndX + ATGM_MOVE_DISTANCE;
            EndY = EndY;
            EndZ = EndZ;
            DestroyCameraForPlayer(playerid);
            SetCameraPosForPlayer(playerid, LocX, LocY, LocZ - ATGM_Z_FIX, EndX, EndY, EndZ, 100, false, false);
            MissileTarget[playerid][0] = EndX;
            MissileTarget[playerid][1] = EndY;
            MissileTarget[playerid][2] = EndZ;
            return 1;
           
    }
    else if(lr < 0)//left
    {
            new Float:LocX, Float:LocY, Float:LocZ;
            new Float:EndX, Float:EndY, Float:EndZ;
            if(HasMissileMoved[playerid] = 0)
            {
                GetPlayerPos(playerid, EndX, EndY, EndZ);
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                HasMissileMoved[playerid] = 1;
            }
            else if(HasMissileMoved[playerid] = 1)
            {
                GetPlayerCameraPos(playerid, LocX, LocY, LocZ);
                EndX = MissileTarget[playerid][0];
                EndY = MissileTarget[playerid][1];
                EndZ = MissileTarget[playerid][2];
            }
            LocX = LocX - ATGM_MOVE_DISTANCE;
            LocY = LocY ;
            LocZ = LocZ;
            EndX = EndX - ATGM_MOVE_DISTANCE;
            EndY = EndY ;
            EndZ = EndZ;
            DestroyCameraForPlayer(playerid);
            SetCameraPosForPlayer(playerid, LocX, LocY, LocZ - ATGM_Z_FIX, EndX, EndY, EndZ, 100, false, false);
            MissileTarget[playerid][0] = EndX;
            MissileTarget[playerid][1] = EndY;
            MissileTarget[playerid][2] = EndZ;
            return 1;
    }
}
OnPlayerCameraFinish() ~Norn
pawn Код:
public OnPlayerCameraFinish(playerid)
{
    if(ControllingMissile[playerid] == 1)
    {
        HasMissileMoved[playerid] = 0;
        ControllingMissile[playerid] = 0;
        DestroyCameraForPlayer(playerid);
        CreateExplosion(MissileTarget[playerid][0], MissileTarget[playerid][1], MissileTarget[playerid][2], 7, 500);
        TogglePlayerControllable(playerid, 1);
        SetCameraBehindPlayer(playerid);
        MissileTarget[playerid][0] = 0.0;
        MissileTarget[playerid][1] = 0.0;
        MissileTarget[playerid][2] = 0.0;
    }
}
What I want to achieve with this code is the ability to move left/right/forward/back with the missile RELATIVE to it's angle (while still maintaining it's downward momentum), and I don't want that angle to change.

My code at the moment moves the camera around in a "dome" sort of shape, which is REALLY hard to actually control, and with the constantly changing camera angles it's bloody disorienting.

Lmao im sure the answer is simple, but im sitting here @ like 3 AM and I have no idea how to proceed

Cheers in advance
Reply
#2

PLSHALPOMG
Reply
#3

-bump
Reply
#4

-Bump
(Sorry I'm on an epic deadline)
Reply
#5

>:CCC ANYONE LMAO
Reply
#6

I'm just going to say, eh? what do you mean? I guess you're trying to make something like a predator missle.
Reply
#7

Similar, It's part of something bigger
But ye the part im stuck on is basically like a COD predator missile
Reply
#8

Ideas more than welcome @ any point LMAO
Reply
#9

You can't really make something like this is SA:MP. SA:MP is server-sided which means there is a delay for every 'message' sent to and from the server. You're never going to get a smooth camera movement, and it's going to cause lag.

P.S It's AGM not ATGM.
Reply
#10

Mate what I have is already smooth enough for me. I have done that by implementing a Z_FIX variable, setting the camera location to lower than the server believes it is at.
What I need to implement is the ability to move my endpoint on a camera-angle related x/y plane, rather than the x/y of the map itself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)