Repository navigation
Conversation
Setting the position or rotation of a moving NPC re-runs move() to aim it at its target again, but it passed only the target and move type, so the speed and stop range fell back to the defaults. An NPC told to walk at walking speed (auto type) started jogging after the first NPC_SetRot, and a driver moving at a custom speed jumped to speed 1.0. move() also wrote the speed into a local that shadowed the moveSpeed_ member, so the member was never set. Store it in the member and pass it, with stopRange_, from setPosition, setVehiclePosition, setRotation and setVehicleRotation.
|
Tested on top of master (72bf89c), NPCs only, going for the setters that aren't in your table. Same idea, A as the reference and B getting the setter every second, distance after 6.5 s: So the stop range is kept too, on master B went 19.7 of the 20 m instead of stopping 8 m before the target. The small gap that's left (B a bit behind A, it's in your numbers too) comes from move() setting lastMove_ to now, so every setter call drops the time since the last update. Not a big deal, just saying where it comes from. LGTM |
|
Thanks for testing the other setters, the stop range one is a good case to have, I only checked speed in game. Good catch on lastMove_, I hadn't looked at that. I'd rather keep this PR to the speed and stop range, but I can look at it in a separate one if it's worth changing. |
Calling
NPC_SetPos,NPC_SetRot,NPC_SetVehiclePosorNPC_SetVehicleRoton a moving NPC resets the speed and stop range it was given inNPC_Move.The setters re-run
move(targetPosition_, moveType_)to aim the NPC at its target again, but they don't pass the speed or the stop range, so the defaults are used.move()also wrote the speed into a localfloat moveSpeed_that shadowed the member, so the member never had the speed to pass anyway.In game:
NPC_MOVE_TYPE_AUTO, NPC_MOVE_SPEED_WALKstarts jogging after the firstNPC_SetRotNPC_MOVE_TYPE_DRIVE, 0.3speeds up to the default 1.0 afterNPC_SetVehicleRotThis stores the speed in the member and passes
moveSpeed_andstopRange_from the four setters.Test
A and B get the same
NPC_Move. Every 2 s, B is given the rotation it already has. Distance covered:The on-foot case in game:
repro.pwn
Tested on a 1.6.7 server with the NPCs component built from master and from this branch.