multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.37k stars 423 forks source link

Peds shooting incorrectly #492

Open ArranTuna opened 5 years ago

ArranTuna commented 5 years ago

Describe the bug Peds are shooting away from the player while they're not supposed to (aimed directly at player's coordinates). This can be "fixed" by alt+tabbing out of SA and back in. A sample script to reproduce the bug included.

To Reproduce peds.zip

I've simplified his test resource, just do /peds and the ped will start shooting at you, but their aim is completely wrong, I added a line between start aim and start end to prove he's meant to be aiming there but it's like he's shooting at you, but isn't.

I've also experienced this problem when making peds that are meant to shoot, this bug basically makes it impossible to have a game mode that relies on fighting peds.

Edit: I've been working with peds again and keep getting this bug so I debugged it some more and turns out that what it's meant to be aiming at is completely wrong to what it should be aiming at, the X Y and or Z randomly become NaN which is why they're usually aiming direction is all wrong. It doesn't happen if stood still but as soon as you start moving the XYZ start becoming NaN.

I was able to successfully mitigate this bug by having the ped stop shooting for 100ms every 1000ms. After he stops shooting, the XYZ stops being a NaN until it happens again in a few seconds time.

Expected behavior To aim at the desired target.

MTA Client: 1.5.3

MTA Server: 1.5.3

Additional context From https://bugs.mtasa.com/view.php?id=4504

T-MaxWiese-T commented 1 month ago

setPedAimTarget does not work properly if it is called less than every 95-100 milliseconds with the standard configuration. If the code is executed while standing somewhere in front of the ped, it hits the player. However, if you move directly back and forth or hide behind a wall and then go somewhere in front of the ped, the ped will no longer hit you. This problem also affects the well-known "Slothman/Slothbot" resource for bots. I read in the Discord that other players also had this problem. But if you execute the code below with a timer only every 95-100 milliseconds then there are no problems. I also tried lowering the <ped_sync_interval> from 400 to 100 but that had no effect. The function setPedAimTarget can be called as often as the <player_sync_interval> is called.

### Steps to reproduce:

  1. Execute this code on the client with the standard configuration:
    local cj = createPed(0, 2498.5, -1684.0, 13.5, 20) -- create a ped at cjs house in grove street
    givePedWeapon(cj, 30, 3000, true)
    function renderHandler()
    local x,y,z = getElementPosition(localPlayer)
    setPedAimTarget(cj, x, y, z)
    setPedControlState(cj, "fire", true)
    end
    addEventHandler("onClientRender", getRootElement(), renderHandler)
  2. Move quickly back and forth or hide behind a wall and then go back in front of the ped or execute the code in another place and then go to the ped.

### Version: Client: v.1.6.0-release-22556 (Windows) Server: v.1.6.0-release-22556 (Windows)

### Possible solution: For the function setPedAimTarget you could add the condition that it is only called as often as the <player_sync_interval> is called so that there are no synchronization problems.