pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.23k stars 326 forks source link

(Slightly different) mouse velocity issues on MacOS 12 #467

Open chromosthete opened 2 years ago

chromosthete commented 2 years ago

Hello ursina users! I'm pretty new to python and ursina engine. I've been having this strange issue when trying to use mouse.velocity or the FirstPersonController prefab. It's similar to #65 in that I am getting whack outputs from mouse.velocity but not quite in the same way. When moving the mouse using the FirstPersonController prefab the camera doesn't really move. I mean it jitters in the direction it should be moving but then it kinda just snaps back. I decided to print mouse.velocity in update() to see what kind of velocities were being reported and I'm not entirely sure if these are wrong but they do really confuse me: Screen Shot 2022-09-27 at 2 41 15 PM This is the output after simply moving the mouse to the right and nothing else. There isn't anything else running in the project. Again, I'm not sure if this is wrong but it seems like it's reporting positive and negative and just all over the place vectors - when again, the mouse was simply moved left. I tried this on some other mice and had the same issue. This doesn't seem to be a problem on my Windows machine. I wonder if it maybe has something to do with the way the mouse is locked? Because it seems like the velocities reported are the initial velocity plus the velocity from the mouse snapping back to the center. I'm not really sure what to do here, all I know is this wasn't an issue when I was using macOS 11 or 10. I've tried re-installing ursina and making a new virtual environment under a different directory and such, it doesn't seem to be making a difference. When I unlock the mouse, mouse.velocity is just stuck at 0. I'm using macOS 12.4, VS Code, an up-to-date version of pip and python, and I've tried restarting my computer and such. Please help, I'm kinda at a loss for what to do

chromosthete commented 2 years ago

After poking around in the code a bit I found how mouse.py gets the velocity when the mouse is locked and it seems like it should work fine so I'm even more confused now

jmugan commented 2 years ago

I'm having mouse velocity issues as well on mac. For me, it is always returning 0.

jmugan commented 2 years ago

My workaround was the use the arrow keys instead. You could add this code to FirstPersonController.update

self.rotation_y += held_keys['right arrow'] - held_keys['left arrow']
self.camera_pivot.rotation_x -= held_keys['up arrow'] - held_keys['down arrow']

I would like to use the mouse on my mac. It worked on my old mac but not on my new mac. Anyone have any suggestions?

magikworx commented 1 year ago

MacOS seems to hate the relative mode. Go to the mouse.py, change the locked.setter function to

    @locked.setter
    def locked(self, value):
        self._locked = value
        if value:
            import platform
            if str(platform.system()) == 'Darwin':
                window.set_mouse_mode(window.M_absolute)
            else:
                window.set_mouse_mode(window.M_relative)
        else:
            window.set_mouse_mode(window.M_absolute)

        if not application.base:
            return

        # print('return', value)
        # self.position = Vec3(0,0,0)
        window.set_cursor_hidden(value)
        application.base.win.requestProperties(window)
        self._locked_mouse_last_frame = True