AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Setting player's camera (https://forums.alliedmods.net/showthread.php?t=312304)

Yoi 11-26-2018 00:05

Setting player's camera
 
Hello, I am newbie, but I really cant get this problem solved.
I want the player's camera, that I can change any way I want (3rd person for example). I tryed to change every game frame like this:

Code:

public OnGameFrame()
{
        GetClientEyePosition(iClient1,vOrigin);
        GetClientEyeAngles(iClient1, vAngles);
        vAngles1 = vAngles;
        GetAngleVectors(vAngles, vAngles1, NULL_VECTOR, NULL_VECTOR);
        NormalizeVector(vAngles1, vAngles1);
        vOrigin[0] = vOrigin[0]-vAngles1[0]*100;
        vOrigin[1] = vOrigin[1]-vAngles1[1]*100;
        vOrigin[2] = vOrigin[2]-vAngles1[2]*100;
        TeleportEntity(iEntity, vOrigin, vAngles, NULL_VECTOR);//iEntity is a camera
}

it would work perfect... if there werent freezes(maybe works better on 100 tick). But I understood that its a bad idea. Next step I tryed to use SetParent:

Code:

public Action:CreateCamera(iClient, args)
{
        iEntity = CreateEntityByName("point_viewcontrol_survivor");       
        DispatchSpawn(iEntity);
        ActivateEntity(iEntity);
        SetVariantString("!activator");
        AcceptEntityInput(iEntity, "SetParent", iClient, iEntity, 0);
        TeleportEntity(iEntity, Float:{ -200.0, 0.0, 70.0}, Float:{ 0.0, 0.0, 0.0}, NULL_VECTOR);
        iCamRef[iClient] = EntIndexToEntRef(iEntity);
        AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "Enable", iClient);
}

It works MUCH better (with some freezes also), but... the rotate point of camera is wrong. The camera rotates around pivot point in the feet. I tryed to google for many days and I didnt find any way to change the rotate point(maybe I am looking bad).
I aslo tryed this code:
Code:

        new hOwnerEntity = GetEntProp(client,Prop_Send,"m_hOwnerEntity");
        SetEntProp(client, Prop_Send, "m_hViewEntity",hOwnerEntity);
        SetEntProp(client, Prop_Send, "m_iObserverMode", 4); // 4 is First person

but I become some kind of spectator and cant shoot and jump.

Maybe its bad idea to use sourcemod for this? Maybe I should use vscript some way? I really dont have any ideas. Pls haelp :shock:

Dragokas 12-04-2018 18:13

Re: Setting player's camera
 
Maybe it help:
https://forums.alliedmods.net/showthread.php?t=297161

++ (from @Silvers)
Code:

// Hooked 3 times, because each alone is not enough, this creates the smoothest play with minimal movement stutter
SDKHook(client, SDKHook_PostThinkPost, onThinkFunk);
SDKHook(client, SDKHook_PreThink, onThinkFunk);
SDKHook(client, SDKHook_PreThinkPost, onThinkFunk);

Is it L4d1 or 2 ?

Yoi 12-06-2018 22:49

Re: Setting player's camera
 
Thank you for answer. The Lux's plugin was the first thing I explored. My 2nd code from previous post is code I writed after reading Lux's .sp. But the problem is, when I SetParent the camera to player, camera rotates around the foots, not around the center of the player.

I don't really know how to work with SDKHook_PostThinkPost, but I found one function in Lux's plugin:
Code:

public Hook_OnPostThinkPost(iClient)
{
        if(!AreClientCookiesCached(iClient))//block everything until async stuff is done
                return;
       
       
        if(!IsPlayerAlive(iClient) || GetClientTeam(iClient) != 2 || !bClientPov[iClient] || !bShouldBePov(iClient))
        {
                if(!IsValidEntRef(iCamRef[iClient]))
                        return;
               
                if(hClientDisableView[iClient] != INVALID_HANDLE)
                        return;
                       
                hClientDisableView[iClient] = CreateTimer(1.0, DisableView, GetClientUserId(iClient));
               
                DisableCam(iClient);
                return;
        }
        else
        {
                if(!IsValidEntRef(iCamRef[iClient]))
                        if(!CreateCamera(iClient))
                                return;
               
                static iModelIndex[MAXPLAYERS+1] = {0, ...};               
                if(iModelIndex[iClient] != GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2))
                {
                        iModelIndex[iClient] = GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2);
                        SetVariantString("eyes");
                        AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "SetParentAttachment");
                }
               
                EnableCam(iClient);
        }
}

I must make something like this 3 times? It is possible to make this work for every-game-frame method? (really don't understand what exactly this function does ^^")

My game is L4D2.

Dragokas 12-08-2018 07:03

Re: Setting player's camera
 
You have to move code of your "OnGameFrame" to a callback of these 3 SDKs. All SDKs shoud point to the same callback. You can see using example in this plugin.
Executing code on each game frame is a very CPU expensive operation.

As about your second code, here is a description of all "point_viewcontrol_survivor" properties:
https://developer.valvesoftware.com/...ntrol_survivor
You can try something, like "SetLocalOrigin".

Also, isn't
Code:

TeleportEntity(iEntity, Float:{ -200.0, 0.0, 70.0}, Float:{ 0.0, 0.0, 0.0}, NULL_VECTOR);
in your code what you was looking for?
X = -200.0, Y = 0.0, Z = 70.0 ? Try change Y.

Also, some discussion and almost finished L4D1 port of Lux's plugin can be found here. Maybe it can help you somehow.

Yoi 12-14-2018 10:26

Re: Setting player's camera
 
I think you don't understand my problem properly - my camera rotates around pivot point. When I making SetParent to player its choosing the axises of pivot from player model. Pivot of player's model located at the foots. So any changes of origin and angles - won't help becase the problem is in the parent. Maybe I can some way attach to the standart camera entity (if it's exist) or any another entity that in the center of player?
My target - is to have custom thirdperson view like in Resident Evil from the shoulder.
P.S. I also tryed those function instead of game frame:
Code:

SDKHook(client, SDKHook_PostThinkPost, onThinkFunk);
SDKHook(client, SDKHook_PreThink, onThinkFunk);
SDKHook(client, SDKHook_PreThinkPost, onThinkFunk);

and it was still laggy.

Dragokas 12-15-2018 09:13

Re: Setting player's camera
 
To control third person camera there are ConVars (unfortunately, it's client side only):
Code:

c_thirdpersonshoulderoffset 20.0
c_thirdpersonshoulderaimdist 120.0
c_thirdpersonshoulderdist 40.0
c_thirdpersonshoulderheight 5
cam_ideallag 0
cam_idealyaw -5
cam_idealdist 20

Maybe it will help you.


All times are GMT -4. The time now is 20:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.