Maintain Arc Rotate camera rotation while changing camera Z position with GUI slider

Hello,

How might I maintain rotation on an ArcRotateCamera when changing camera Z position using a GUI panel slider?

Here’s the very basic code:
slider.onValueChangedObservable.add(function(value) {
camera.setPosition(new BABYLON.Vector3(0,0,-10+value));
});

Thanks,

Galen

Hiya Galen, welcome to the BJS forum!

Umm… I have an idea. When you move camera.position.z, also move camera.target.z… the exact same amount. Might work. :slight_smile:

You might want/need to set an invisible targetMesh as camera.target, and then just move targetMesh the same AMOUNT as you move camera.position.

Also, you might wish to set camera.lockedTarget = camera.target… or maybe camera.lockedTarget = targetMesh.position. THEN… MAYBE… you only need the slider to move the (invisible) target itself, and the camera will move WITH IT.

I’m not an expert in using camera.lockedTarget… sorry. You’ll need to read docs, search playgrounds, and do tests… to learn its full story. :slight_smile:

Goof around with that stuff… and report back, as wanted. Other/Better replies might come soon.

Hey @Wingnut,

Long time! I hope you are doing well. I don’t have any issue with maintaining my camera target; however, I played around with it for the past 30 minutes anyway. I’ve tried to do this with a Universal camera and other types, but with no luck. It can’t be that hard, right?

Cheers,

Galen

1 Like

https://www.babylonjs-playground.com/#HATGQZ#20

Like this?

Hi guys.

First, @Rah, Galen doesn’t want the camera to turn… when the z-zooming happens.

https://www.babylonjs-playground.com/index.html#HATGQZ#22

Yours is turning. :slight_smile: You need to move camera.target the same amount… and you shouldn’t force camera x and y to zero, as that over-rides CURRENT camera x/y. I adjusted that… in #22. :slight_smile:

Galen… good to see you again, too. I’ve been well, thx. Yourself?

I tried one… https://www.babylonjs-playground.com/#3VMTI9#37

Added line 243… and then installed some good greasy code-lines in 254-259.

I think it’s working, but it’s Monday, which means I’m not fully operational. :smiley:

1 Like

Yeah just as i came back to reread the question, as you posted. lol

Anyway uh not sure why the others turn, but this one doesnt

https://www.babylonjs-playground.com/#HATGQZ#26

Wait nvm… gimme a minute

Seems to be an optical illusion?

https://www.babylonjs-playground.com/#HATGQZ#27

1 Like

heh. No sneaking-in that camera.position = new BABYLON.Vector3(0,0,0); in line 10, Rahmeister. :slight_smile:

Camera must use CURRENT position… set in line 8. Then add to that.

https://www.babylonjs-playground.com/#HATGQZ#28 Still turning. :slight_smile:

You must move camera.target, too. And yes, when camera.position is perfectly x/y-aligned with cam target x/y… then moving z position won’t turn the camera. You’ll need to set the camera at a weird angle, and do your tests from there, I suppose. :slight_smile:

2 Likes

Haha yeah i wanted to make sure haha gotta have a good starting position :slight_smile:

However what i meant was check the console, the camera is not actually rotating, nor are the cubes(spheres), there must be some kind of internal math that is changing like zoom on a camera…

1 Like

It looks like an illusion of perspective to me, as it only seems to “rotate” when viewing a corner. When zooming from one of the 90 degree angles on a flat face it seems to just zoom in and out how you’d expect.

But your guesses are as good as mine :joy:

2 Likes

@Rah and @Wingnut

I really appreciate the assistance with this. As I’m not at all familiar with the babylon.js GUI panels, it took me a few minutes to figure out what the heck @Rah was doing. However, I picked the PG scene apart and scaled it back allot to get at the heart of the solution.

https://www.babylonjs-playground.com/#HATGQZ#67

The issue, however, is that when I rotate the camera and then move the slider, the rotation remains the same. I haven’t yet figured out the math to hold camera rotation which was my initial problem, so your HUGE brains might come up with a solution before I do. Also, I gotta make some eggs as I’ve been up coding all night.

Don’t know how much more brain power I have right now… but will try to keep going once I get some little chickens in my gullet.:yum:

Cheers,

Galen

Sorry if I don’t quite understand your question, but can’t you just change the camera.radius? perhaps in combination with changing the z-value?

1 Like

@Sme,

DK and other devs might remember that I don’t do my best work when I don’t sleep (or eat). Yes, attaching the value of the slider to the camera radius works fine.:grin:

It’s been so long since I’ve worked in BJS, that I overlooked this.

Thank you!

Galen

1 Like

@Galen Good to hear haha. Yeah, we’ve all been there before… sleep is important haha. Food too :smile: