Walking Cop with Nitestick ( npc )

Started by habi, May 06, 2023, 05:12 AM

Previous topic - Next topic

habi

Hi i made a walking cop with nitestick. See video:

Ingredients:
1 cup of SetAnim served in a NewTimer dish which is 100ms.
Keep the fire burning at npc's kitchen by GetMyPos()+(target-GetMyPos()).Normalised()*0.14
i will post the full recipe sometimes later

Ridwan Rz

It's time to make some noise huh?  ;D  ;D

PSL

GetMyPos()+(target-GetMyPos()).Normalised()*0.14
What does this code mean and what is Normalised like?
Is the 0.14 behind walking every 100ms distance?

habi

#3
Quote from: PSL on Sep 29, 2023, 02:40 AMWhat does this code mean and what is Normalised like?
Is the 0.14 behind walking every 100ms distance?
Yes, 0.14 is the reason why the cop will appear walking even to players who stream in later. It is syncing.

Here is a look at the code. The complete code is put somewhere in npc-wiki.
function step_forward()
{
local newpos=GetMyPos()+(target-GetMyPos()).Normalised()*0.14;
newpos.z=FindZFor2DCoord(newpos.x, newpos.y)+1.0425;
SetLocalValue(V_POS, newpos);
SetLocalValue(F_ANGLE, atan2(-(target.x-GetMyPosX()),target.y-GetMyPosY()));
...
        SendOnFootSyncDataLV();
       ...
}
This function is called every 100 msec.
Normalized convert it into unit vector.
So multiplying by 0.14 is distance of one walking step
So newpos = oldpos + one step forward