AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Resolved] Entity move formula (https://forums.alliedmods.net/showthread.php?t=65376)

hlstriker 01-07-2008 03:37

[Resolved] Entity move formula
 
I'm really not good with vector formulas, and I'm trying to figure out how to move an entity around similar to how EntMod moves entities.

I know how to make the entity move in straight lines, but getting it to follow the angle I'm looking while moving my player around is what gets me.

Here is the code I came closest to working but is still way off:
PHP Code:

static Float:playerOrigin[3], Float:playerAngles[3], Float:retVec[3];

pev(idpev_originplayerOrigin);
pev(idpev_anglesplayerAngles);

angle_vector(playerAngles1retVec);

retVec[0] *= playerOrigin[0];
retVec[1] *= playerOrigin[1];
retVec[2] *= playerOrigin[2];

engfunc(EngFunc_SetOriginentityretVec); 


ConnorMcLeod 01-07-2008 03:55

Re: Entity move formula
 
You could have a look at this plugin : http://djeyl.net/forum/index.php?showtopic=50982

hlstriker 01-07-2008 05:16

Re: Entity move formula
 
Thanks a lot, connorr :)

I was able to get the formula from that plugin. I converted it to use floats instead of integers so it's more accurate.

Here it is if anyone else wants it:
PHP Code:

static Float:origin[3], Float:aimVec[3], Float:entOrigin[3], Float:direction[3], Float:length;
static 
Float:moveTo[3], Float:Mins[3], Float:Maxs[3], distance;

pev(idpev_originorigin);
pev(isMovingEnt[id], pev_originentOrigin);
fm_get_aim_origin(idaimVec);

direction[0] = aimVec[0] - origin[0];
direction[1] = aimVec[1] - origin[1];
direction[2] = aimVec[2] - origin[2];
length get_distance_f(aimVecorigin);

// Avoid division by 0
if(length == 0.0)
    
length 1.0;

distance 200// Set how close you want the ent to be to you
moveTo[0] = origin[0] + direction[0] * distance length;
moveTo[1] = origin[1] + direction[1] * distance length;
moveTo[2] = origin[2] + direction[2] * distance length;

pev(isMovingEnt[id], pev_minsMins);
pev(isMovingEnt[id], pev_maxsMaxs);
moveTo[0] -= (Mins[0] + Maxs[0]) * 0.5;
moveTo[1] -= (Mins[1] + Maxs[1]) * 0.5;
moveTo[2] -= (Mins[2] + Maxs[2]) * 0.5;

engfunc(EngFunc_SetOriginisMovingEnt[id], moveTo); 



All times are GMT -4. The time now is 11:13.

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