Senior Member
Join Date: Dec 2020
Location: Brazil
|
11-22-2023
, 20:22
[L4D2]Rotating Objects around player
|
#1
|
Could anyone help me with the rotations of objects with speeds?
I was trying to create a rotation scheme for the tank's rocks, in which they float around the tank, outlining it. There are eight rocks that keep rotating.
PHP Code:
//Spawn Rocks
for(int i = 1; i <= 8; i++)
{
entity[i] = CreateEntityByName("prop_physics_override");
if(entity[i] != -1)
{
char tName[64];
Format(tName, sizeof(tName), "TSE%d", client);
DispatchKeyValue(client, "targetname", tName);
GetEntPropString(client, Prop_Data, "m_iName", tName, sizeof(tName));
SetEntityModel(entity[i], Model);
DispatchKeyValue(entity[i], "targetname", "FollowEntity");
DispatchKeyValueVector(entity[i], "origin", vPos);
DispatchKeyValueVector(entity[i], "Angles", vAng);
DispatchKeyValue(entity[i], "parentname", tName);
DispatchKeyValue(entity[i], "parentname", tName);
DispatchKeyValue(entity[i], "solid", "0");
AcceptEntityInput(entity[i], "TurnOn");
DispatchSpawn(entity[i]);
followPosition[0] = followRadius * Cosine( DegToRad( followAngle )) + vPos[0];
followPosition[1] = followRadius * Sine( DegToRad( followAngle )) + vPos[1];
followPosition[2] = vPos[2];
TeleportEntity(entity[i], followPosition, vAng, NULL_VECTOR);
followAngle += incRadius; // next point attachment
}
SetEntityRenderColor(entity[i], sColor[0], sColor[1], sColor[2], sColor[3]);
GlowTarget(entity[i], sGlow[0], sGlow[1], sGlow[2]);
ClientModel[client][number][i-1] = EntIndexToEntRef(entity[i]);
}
DataPack hPack = new DataPack();
hPack.WriteCell(GetClientUserId(client));
hPack.WriteCell(number);
hPack.WriteFloat(Pos[2]);
CreateTimer(0.01, TimerRotation, hPack, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
//
//TimerRotaion
Action TimerRotation(Handle timer, DataPack hPack)
{
hPack.Reset();
int client = GetClientOfUserId(hPack.ReadCell());
if(!IsTank(client)) return Plugin_Stop;
int number = GetClientOfUserId(hPack.ReadCell());
int entity[9];
float vAng[9][3], vVel[9][3], vPos[3], NewPos, EntityPos[9][3];
GetClientAbsOrigin(client, vPos);
NewPos = hPack.ReadFloat();
vPos[2] += NewPos;
for(int i = 1; i <= 8; i++)
{
entity[i] = EntRefToEntIndex(ClientModel[client][number][i-1]);
if(!IsValidEntRef(entity[i])) continue;
if(!IsValidEntity(entity[i])) continue;
GetEntPropVector(entity[i], Prop_Data, "m_vecOrigin", EntityPos[i]);
GetEntPropVector(entity[i], Prop_Data, "m_angRotation", vAng[i]);
GetEntPropVector(entity[i], Prop_Data, "m_vecVelocity", vVel[i]);
if(vAng[i][1] >= 360.0) vAng[i][1] = 0.0;
else vAng[i][1] += 3.6;
if ( EntityPos[i][2] < vPos[2] )
{
vAng[i][0] = -5.0;
GetAngleVectors( vAng[i], vVel[i], NULL_VECTOR, NULL_VECTOR);
NormalizeVector( vVel[i], vVel[i] );
vAng[i][0] = 0.0;
}
else if ( EntityPos[i][2] > ( vPos[2] + 45.0 ))
{
vAng[i][0] = 5.0;
GetAngleVectors( vAng[i], vVel[i], NULL_VECTOR, NULL_VECTOR);
NormalizeVector( vVel[i], vVel[i] );
vAng[i][0] = 0.0;
}
else
{
vAng[i][0] = 0.0;
GetAngleVectors( vAng[i], vVel[i], NULL_VECTOR, NULL_VECTOR);
NormalizeVector( vVel[i], vVel[i] );
}
ScaleVector(vVel[i], 90.0);
TeleportEntity( entity[i], NULL_VECTOR, vAng[i], vVel[i] );
}
return Plugin_Continue;
}
void GlowTarget(int entity, int R, int G, int B)
{
SetEntProp(entity, Prop_Send, "m_glowColorOverride", R + (G * 256) + (B * 65536));
SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
SetEntProp(entity, Prop_Send, "m_nGlowRange", 3000);
SetEntProp(entity, Prop_Send, "m_nGlowRangeMin", 0);
}
I don't know if is this correct
__________________
_________________
Discord: gabrielbr007
YouTube: WhiteFire
Steam: WhiteFire
Last edited by King_OXO; 11-27-2023 at 19:17.
|
|