Skip to content

Return the NPC's velocity from NPC::getVelocity - #1292

Open
r4sheed wants to merge 1 commit into
openmultiplayer:masterfrom
r4sheed:fix/npc-get-velocity
Open

r4sheed wants to merge 1 commit into
openmultiplayer:masterfrom
r4sheed:fix/npc-get-velocity

Conversation

@r4sheed

@r4sheed r4sheed commented Nov 4, 2026

Copy link
Copy Markdown

NPC::getVelocity returned the player's position, so NPC_GetVelocity gave back the NPC's coordinates instead of its velocity. It now returns velocity_, the value setVelocity writes and the syncs send. Only reads of an NPC's velocity are affected

@GuiBoneVowt

Copy link
Copy Markdown

Tested on top of master (72bf89c), Windows. First with a script and NPCs only, then in game (0.3.7-R5) with the values on a textdraw while the NPC walked, sprinted and drove around next to me.

On master NPC_GetVelocity just hands back the position (1495.0, 1395.0, 10.8 for an idle NPC standing there, and it keeps following the position while it moves). With this PR:

  • idle: 0, 0, 0
  • right after NPC_SetVelocity(0.1, 0.2, 0.0): 0.1, 0.2, 0.0, then 0 on the next tick, which is expected since that's a one-off push
  • walking and sprinting with NPC_Move: 0.00155 and 0.00926 (the sign flips when it turns around), same as GetPlayerVelocity for the NPC and it matches how fast it actually moves (units per ms)
  • after NPC_StopMove and after it reaches the target: 0

One thing I noticed while driving with NPC_Move: NPC_GetVelocity gives 0.00999 but GetVehicleVelocity on the car gives 0.19999, because sendDriverSync multiplies it by 20 and the getter doesn't. Not sure if that's meant to stay that way, but a script reading an NPC's speed in a car gets a number 20x smaller than the vehicle's. Probably fine as a follow-up, the fix itself LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants