fireclawthefox / panda3d-character-controller

8 stars 4 forks source link

CAMERA GLITCH #4

Closed GORILLASTIXS closed 2 years ago

GORILLASTIXS commented 2 years ago

Hello Sir,

Thank you for this very helpful and applicable tutorial. I want to get going on a project by using some of these templates. As I start the demo.py code, the camera rotates around uncontrollably. Could you please help me? I've been up all day trying to figure it out. Any tips would be great. Thanks again!

fireclawthefox commented 2 years ago

Hi, if you could give me a few more details, I'll try to help you find the problems source. First of, which operating system are you on, which version of panda3d and python do you use and is your mouse cursor catched within the window. Also check if the camera stops spinning if you pause the demo and then unpause it again (press P twice). Finally, does this only happen in one camera mode for example third person mode or is it applicable for both, third and first person?

GORILLASTIXS commented 2 years ago

Thank you for getting back to me! My OS is Ubuntu 20.04.3 LTS and python 3.8 as the interpreter. This occurs the moment I run the demo, which I downloaded as a zip. When I press F2, the camera is stable and allows me to control the fox in first person camera.

fireclawthefox commented 2 years ago

Stays the camera stable if you press F2 to get back to third person mode again?

Maybe this is some kind of bug at the initialization. Can you check where your mouse pointer is at the time you start the application and does the spinning change if you move your mouse?

GORILLASTIXS commented 2 years ago

It goes back to the glitch right after I press F2 again. My mouse can be seen before the game starts and pauses. Moving the mouse affects the direction of the camera slightly but it reverts back immediately to that state.

fireclawthefox commented 2 years ago

ok, few more things to check.

  1. in the src/characterController/cameraPlugins/CameraThirdPerson.py script add the following print statement around line 137, right after the mw = base.mouseWatcherNode() print(mw.getMouse())

This will print the mouse position every frame. If you haven't moved your mouse, this should always be 0,0

  1. within the if blocks if cam_left and elif cam_right in the same file add a print statement to see if any of the two is active

Those should be the only places in which the camera gets moved horizontally, except for the collision detection, but I guess one of those could cause the problem.

GORILLASTIXS commented 2 years ago

After following these instructions, these are the values that I am getting from the print statements. These are outputs without moving the mouse.

Screenshot from 2022-01-20 13-47-35

fireclawthefox commented 2 years ago

ok, somethings definitely off with your mouse position. Can you now print the value of the following self.core.getConfig("win_width_half") This should represent the width of your window divided by 2. From what I see I think your window is 800x600 so this should read 400.

GORILLASTIXS commented 2 years ago

I added that print statements to various functions, got a couple errors. I then commented some of the print statements out and left one under def pauseCamera(self). This stabilized my camera. My values print out to LPoint2f(0,0), as opposed to the image before. Would you happen to know if this is a valid solution or if the code would be prone to breaking in future events?

Print statement: print(self.core.getConfig("win_width_half" + "pause camera"))

Screenshot from 2022-01-20 18-08-22

LPoint Values: Screenshot from 2022-01-20 18-20-13

fireclawthefox commented 2 years ago

That shouldn't make any difference at all since it's only called if you pause the player in first person mode and also will it break the pause for first person mode since you try to access a configuration that doesn't exist.

Is that the only change left in your code by now or are there changes in other files?

GORILLASTIXS commented 2 years ago

I haven't changed anything since I cloned this repo. The problem seems to occur when I enter into full screen. When I minimize the window, the code works fine.

fireclawthefox commented 2 years ago

Ah, can you check if the window size given with base.win.getSize() in fullscreen is the same as when it's windowed?

GORILLASTIXS commented 2 years ago

How would I go about doing this?

These are the only instances where I see base.win.getSize():

1). base.win.movePointer(0, base.win.getXSize() // 2, base.win.getYSize() // 2)

2). def togglePause(self): """This function shows how the app can pause and resume the player""" if self.pause:

to respect window size changes we reset the necessary variables

        _**self.playerController.win_width_half = base.win.getXSize() // 2**_
        **_self.playerController.win_height_half = base.win.getYSize() // 2_**
fireclawthefox commented 2 years ago

Just add a print(base.win.getSize()) somewhere. Shouldn't matter much where. You can for example add it in the task where you have printed the mouse position previously. I just need the output once at Fullscreen and once from Windowed mode.

GORILLASTIXS commented 2 years ago

LVecBase2i(840, 704) - Regular LVecBase2i(1294, 704) - Fullscreen

fireclawthefox commented 2 years ago

Hm, strange values for a fullscreen resolution. Are those correct for you screen and window?

fireclawthefox commented 2 years ago

Ah, another thing you can try is copying the following code to set the half window size variables in the task where the camera gets updated, just somewhere at the start like, at the place you added the first print statement.

self.core.setConfig("win_width_half", base.win.getXSize() // 2)
self.core.setConfig("win_height_half", base.win.getYSize() // 2)
GORILLASTIXS commented 2 years ago

I added both statements under the thirdPersonCam pauseCamera function. When I run the code, the camera still glitches, but when I then pause the camera, that stabilizes is the scene without any glitch.

GORILLASTIXS commented 2 years ago

Once I moved the XSize and YSize to updateCamera instead of pauseCamera, the code ran without any issues. Thank you for the help!

fireclawthefox commented 2 years ago

hm, ok. May you send me the changed files so I can have a look at them? I'm still wondering how this can happen.

GORILLASTIXS commented 2 years ago

Not sure why this fixed it, but whenever I comment out the two statements the code bugs outs. Doing the opposite allows the code to run properly. How would you like me to send the code? Copy and paste? Screenshot? Email?

fireclawthefox commented 2 years ago

Just paste the files here or as a gist https://gist.github.com/ would be fine.

fireclawthefox commented 2 years ago

@Haitianwarrior do you still have the changes and would be so kind to send them to me? Otherwise I'll close this issue for now.