How to implement camera pitch by moving mouse in roaming-ralph?

Just like the title.
Any code demo please?

Have you searched the forum for such? I do think that there are examples to be found.

Yes,I have searched the forum.
But I just find some code snippets implement FPS camera (Not TPS) or implement camera pitch by keyboard(not by moving mouse)…

Did you try this post ? If it’s not exactly what you want, it should provide a nice starting point i guess

2 Likes

Thanks,that helps a lot.
But there remains a problem,the pointer will move out of the window if we moved mouse a little faster.
How can we deal with it?

You can set the mouse mode to “confined” mode to address this. Be sure to give the user a way to go back to the normal mouse mode, eg. in a pause screen.

1 Like

This seems more concise and simplest way to do it: orbiting camera controls

Although be aware that the example linked above makes some assumptions about the window-size and the speed of rotation, and seems to be implementing rotation around a model at the centre of the view, rather than rotation of an outward-looking view.

(It also doesn’t use a class-based approach, but that’s a matter of personal style.)

Still, it is a fairly simple example if those things are accounted for.

Not sure what you mean by speed of roation. It seems to be using deltaTime. If you mean some values are hardcoded, then I understand, but for code snippets hardcoded values just reduce lines of code.

Exactly, I do believe.

And indeed, it does simplify the code. I just think that such assumptions in the code are at least worth pointing out for the sake of clarity.

And to be clear, I’m not saying that it’s bad that those assumptions are present–not at all. I just feel it worth noting that they’re there for the sake of people using the snippet in question.

(The window-size assumption is one that I could particularly see new devs missing, leading to their being confused when it appears to misbehave in a window of different size. Thus it seems worth bringing a little attention to the assumption.)

This is something that I think that people might debate about: You’re right that it does reduce the number of lines of code, which may aid clarity–but conversely, it makes the function of the values in question less readily-apparent, which may hinder clarity. And as I say, which effect is more prominent is something that I think that people might debate one way or another.