View Single Post
Author Message
Yoi
Junior Member
Join Date: Nov 2018
Location: Russia
Old 11-26-2018 , 00:05   Setting player's camera
Reply With Quote #1

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
Yoi is offline