mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

Fix getPedMoveState returns incorrect move states

Open Unde-R opened this issue 4 years ago • 38 comments

This should fix the following issues: #1598 #1594 #1590

Unde-R avatar Aug 07 '20 11:08 Unde-R

Thanks for your PR. I'm sure this will be fine but I'll need to do some extensive testing later just to make sure it doesn't unintentionally break anything else. Good work though!

Lpsd avatar Aug 07 '20 11:08 Lpsd

Thanks for your PR. I'm sure this will be fine but I'll need to do some extensive testing later just to make sure it doesn't unintentionally break anything else. Good work though!

Thanks mate

Unde-R avatar Aug 07 '20 11:08 Unde-R

I tested a code to get groundposition and compared it with player's Z position in the areas which return "fall" and here is the results ( Z - groundposition ) : 1,00000095367 1.00000095367 1.00000095368

Unde-R avatar Aug 07 '20 18:08 Unde-R

thanks for submitting this. quick question for future documentation / reproduction purposes, please can you provide the coordinates you tested with? thank you :)

qaisjp avatar Aug 07 '20 18:08 qaisjp

thanks for submitting this. quick question for future documentation / reproduction purposes, please can you provide the coordinates you tested with? thank you :)

sure one moment

Unde-R avatar Aug 07 '20 18:08 Unde-R

Ground Position: 14.250931739807
Player Position: 2221.7590332031, -1653.4652099609, 15.250932693481
-------------
Ground Position: 14.252799987793
Player Position: 2221.814453125, -1653.5106201172, 15.252800941467
-------------
Ground Position: 14.287864685059
Player Position: 2223.142578125, -1653.3934326172, 15.287865638733

Unde-R avatar Aug 07 '20 18:08 Unde-R

I added MOVEMENTSTATE_ROLL because It was declared but no code for It.

  • [x] crouch-roll
  • [x] crawl-roll

Result: https://pastebin.com/vz4zQb3D

Unde-R avatar Aug 11 '20 14:08 Unde-R

This is absolutely amazing!

Einheit-101 avatar Aug 11 '20 16:08 Einheit-101

Looks like this issue should be fixed too #534

Unde-R avatar Aug 14 '20 20:08 Unde-R

Thanks for the help! Tested It's working fine now.

Unde-R avatar Aug 14 '20 21:08 Unde-R

The suggested code I provided is not correct. Please read https://github.com/multitheftauto/mtasa-blue/pull/1603#discussion_r467206465

qaisjp avatar Aug 15 '20 12:08 qaisjp

The suggested code I provided is not correct. Please read #1603 (comment)

return (vecPosition.fZ > fGroundLevel && (vecPosition.fZ - fGroundLevel - 1.0f) <= ((fabs(vecPosition.fZ) < fabs(fGroundLevel) ? fabs(fGroundLevel) : fabs(vecPosition.fZ)) * FLOAT_EPSILON)); Thoughts on this?

Unde-R avatar Aug 15 '20 14:08 Unde-R

Almost there! Remember, there's two checks here. One that checks vecPosition.fZ > fGroundLevel, and another that checks (vecPosition.fZ - fGroundLevel) <= 1.0f.

I think this should be split up into two if-s, with correct float comparisons.

To be honest, the code is a bit hard to read, so perhaps you should add helpers like these* to Utils.cpp or Utils.h.

Then you can do something like this:

    // We don't care if the ped is underground
    if (definitelyGreaterThan(vecPosition.fZ, fGroundLevel))
        return false;
        
    // Check (vecPosition.fZ - fGroundLevel) <= 1.0f
    return definitelyLessThan(vecPosition.fZ - fGroundLevel, 1.0f) || essentiallyEqual(vecPosition.fZ - fGroundLevel, 1.0f);

I'm not sure if this best practice, but it's the best thing I can come up, and I feel like it's better than just adding 0.001 and calling it a day.

[*] this link is from "Swift", but it is actually some chat software, and not the Swift Programming Language

qaisjp avatar Aug 23 '20 16:08 qaisjp

    // We don't care if the ped is underground
    if (definitelyGreaterThan(vecPosition.fZ, fGroundLevel))
        return false;
        
    // Check (vecPosition.fZ - fGroundLevel) <= 1.0f
    return definitelyLessThan(vecPosition.fZ - fGroundLevel, 1.0f) || essentiallyEqual(vecPosition.fZ - fGroundLevel, 1.0f);

I tried this ^^ but somehow It's not working properly.

Unde-R avatar Aug 23 '20 20:08 Unde-R

// We don't care if the ped is underground
    if (definitelyGreaterThan(vecPosition.fZ, fGroundLevel))
        return false;

Looks like It's because of this.

Unde-R avatar Aug 23 '20 20:08 Unde-R

Do this (like in the CVector class):

abs(vec.z) - abs(groundposz) >= FLOAT_EPSILON

This is totally acceptable, as float epsilon is a thing in CS

Pirulax avatar Aug 23 '20 20:08 Pirulax

    // We don't care if the ped is underground
    if (definitelyGreaterThan(vecPosition.fZ, fGroundLevel))
        return false;

The code I suggested had a small mistake.

It doesn't work because we're returning false if our z-position is greater than the ground level. That does not match up to the comment that says "we don't care if the ped is underground"?

It should return false if the ped is underground. But we're not checking if the ped is underground correctly.

you should use definitelyLessThan instead :)

qaisjp avatar Aug 23 '20 20:08 qaisjp

Yeah I'll update it soon. What about crouch-roll should I keep it here or make another PR for it?

Unde-R avatar Aug 23 '20 21:08 Unde-R

What about crouch-roll should I make another PR for it?

Good idea

qaisjp avatar Aug 23 '20 22:08 qaisjp

Good idea

I'll open a PR rn

Unde-R avatar Aug 24 '20 13:08 Unde-R

This is tested a lot and seems to be fine, why is this not merged yet?

Einheit-101 avatar Apr 25 '22 00:04 Einheit-101

This is tested a lot and seems to be fine, why is this not merged yet?

No accepted reviews, and no testing beyond the stale ones has been made. I am interested to hear if this actually resolves the three linked issues and how does it do that since it is not apparent from the description. This leaves me to have to thoroughly delve into the code to figure out whats going on, how to test it and how to try to break it. None of which I have time to do right now personally.

patrikjuvonen avatar Apr 25 '22 00:04 patrikjuvonen

I could test functionality with a working build if i can get one. My resource uses these functions.

Einheit-101 avatar Apr 25 '22 02:04 Einheit-101

@patrikjuvonen

Tested on nightly (Multi Theft Auto v1.5.9-release-21251 - but the version shouldn't matter, since it exists on stable as well)

#1598 - fixed build & nightly build #1594 - fixed build & nightly build #1590 - fixed build & nightly build

Besides those locations, i've tested whether it happens in the other places, which haven't been mentioned. And it seems that fix works well.

ds1-e avatar Jun 23 '22 11:06 ds1-e

@patrikjuvonen

Tested on nightly (Multi Theft Auto v1.5.9-release-21251 - but the version shouldn't matter, since it exists on stable as well)

#1598 - fixed build & nightly build #1594 - fixed build & nightly build #1590 - fixed build & nightly build

Besides those locations, i've tested whether it happens in the other places, which haven't been mentioned. And it seems that fix works well.

I think you shared the wrong nightly build video for 1598, it's the same as 1594. Tests should be equal.

patrikjuvonen avatar Jun 23 '22 13:06 patrikjuvonen

I don't think 1594 is fixed by this PR (based on the video above). Why is it returning false for move state when the move state is supposed to be something specific? It will still be causing the same headache.

patrikjuvonen avatar Jun 23 '22 13:06 patrikjuvonen

I don't think 1594 is fixed by this PR (based on the video above). Why is it returning false for move state when the move state is supposed to be something specific? It will still be causing the same headache.

because of this https://github.com/multitheftauto/mtasa-blue/pull/1603/files#diff-25862afc0e3088d4619017944046a0d75c9a75a9ffbdb666216bb3a9478453fdR2381

Unde-R avatar Jun 23 '22 13:06 Unde-R

I don't think 1594 is fixed by this PR (based on the video above). Why is it returning false for move state when the move state is supposed to be something specific? It will still be causing the same headache.

basically in the video of the fixed build, he was standing at first then he's trying to enter the vehicle thats why its showing false, because he's entering the vehicle

        else if (IsEnteringVehicle())
            return MOVEMENTSTATE_UNKNOWN;

Unde-R avatar Jun 23 '22 13:06 Unde-R

Exactly. I don't understand why it has been specified as unknown. If the ped is jogging to enter a vehicle, shouldn't it return jogging?

patrikjuvonen avatar Jun 23 '22 14:06 patrikjuvonen

@patrikjuvonen i guess qaisjp agreed upon making it false

He also suggested it:

Vehicle-related movement states

Note that getPedMoveState documents what happens when the player is in a vehicle:

    Returns a string indicating the ped's move state, or false if the ped is not streamed in, the movement type is unknown, the ped is in a vehicle or the ped is invalid.

Basically, I'm not 100% sure whether enter_vehicle and leave_vehicle fits well with the rest of these move states. What do you think?

ds1-e avatar Jun 23 '22 14:06 ds1-e