python-airmash icon indicating copy to clipboard operation
python-airmash copied to clipboard

player rotation sometimes 0?

Open will-emmerson opened this issue 7 years ago • 3 comments

I have a strange problem in that player.rotation doesn't seem to be updating. I have some simple code in the client which moves a bit and prints out x,y and rot:

            logging.info(f'THREAD x:{client.player.posX} y:{client.player.posY} rot:{client.player.rotation}')
            client.key('RIGHT', True)
            client.key('UP', True)
            self.wait(1)
            client.key('RIGHT', False)
            client.key('UP', False)

And I also print out x,y and rot on update:

@client.on('PLAYER_UPDATE')
def on_update(client, msg):
    if msg.id == client.player_id:
        logging.info(f'UPDATE x:{msg.posX} y:{msg.posY} rot:{msg.rot}')

But for some reason player.rotation is quite often 0 even when message.rot isn't:

25.298 INFO     START BOT
25.910 INFO     UPDATE x:-995.3671875 y:-3114.568359375 rot:0.0
26.302 INFO     THREAD x:-995.3671875 y:-3114.568359375 rot:0.0
26.324 INFO     UPDATE x:-995.3671875 y:-3114.568359375 rot:0.0
26.472 INFO     UPDATE x:-995.3671875 y:-3114.568359375 rot:0.00030517578125
27.328 INFO     UPDATE x:-840.345703125 y:-3139.748046875 rot:3.91357421875
27.415 INFO     UPDATE x:-840.33984375 y:-3139.736328125 rot:3.91357421875
28.307 INFO     THREAD x:-840.33984375 y:-3139.736328125 rot:0      <-------
28.329 INFO     UPDATE x:-782.83203125 y:-3040.529296875 rot:3.91357421875
28.372 INFO     UPDATE x:-782.830078125 y:-3040.52734375 rot:3.91387939453125
29.330 INFO     UPDATE x:-899.068359375 y:-3108.3828125 rot:1.53350830078125
29.484 INFO     UPDATE x:-899.0625 y:-3108.400390625 rot:1.53350830078125
30.312 INFO     THREAD x:-899.0625 y:-3108.400390625 rot:0      <-------
30.334 INFO     UPDATE x:-869.271484375 y:-3215.416015625 rot:1.53350830078125
30.334 INFO     UPDATE x:-869.26953125 y:-3215.419921875 rot:1.533966064453125
30.685 INFO     DEAD

UPDATE is coming from update function and THREAD is coming from the thread. You can see that at 28.307 the rot is 0 even though a second before it was 3.9135. It happens again at 30.312.

Am I just being stupid?

will-emmerson avatar Jan 04 '18 15:01 will-emmerson

I can't see anything immediately obvious, so the chances are you're not being stupid. I'll rig up a test and look into it tonight.

Gadgetoid avatar Jan 04 '18 17:01 Gadgetoid

Looks like some updates are changing it to 0, this is the output I get from just watching a change on rotation:

Rotation: 5.04577636719
Rotation: 3.50173950195
Rotation: 0
Rotation: 1.962890625
Rotation: 0.419006347656
Rotation: 0
Rotation: 5.16372680664
Rotation: 3.60809326172
Rotation: 0
Rotation: 2.06039428711
Rotation: 0.525665283203
Rotation: 0
Rotation: 5.26947021484
Rotation: 3.7141418457
Rotation: 0
Rotation: 2.1711730957
Rotation: 0.621490478516
Rotation: 0
Rotation: 5.38055419922
Rotation: 3.83056640625

I'll find out which packets are responsible- perhaps their rotation data is generally invalid.

Gadgetoid avatar Jan 04 '18 17:01 Gadgetoid

As expected, it was me being stupid. Not you.

A 0 rotation was appearing when the player class was updateed with a dataset that didn't include a value for 'rot'. Since it looked for a pre-existing value in self.rot when the internal name for rotation is actually self.rotation it ended up defaulting to 0, rather than keeping the valid, existing value.

I've fixed this by renaming 'rot' to 'rotation' across all the packet definitions, which was something that had bugged me for a while anyway.

See: https://github.com/Gadgetoid/python-airmash/commit/b2201fe0202423f6c97d41440b26f7b30d269de9

Gadgetoid avatar Jan 04 '18 18:01 Gadgetoid