# PointerLock with camera Z up

**URL:** <https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770>\
**Category:** Questions\
**Tags:** camera-controls\
**Created:** [February 5, 2018, 9:24am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770 "2018-02-05T09:24:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![guybou](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@guybou](https://discourse.threejs.org/u/guybou)\
**Post date:** [February 5, 2018, 9:24am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/1 "2018-02-05T09:24:05Z")

</div>

I’m trying to use the PointerLock controls however my camera Z vector is up, how can I modify it to work properly?

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [February 5, 2018, 9:29am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/2 "2018-02-05T09:29:49Z")

</div>

It would be great to have more information and a [Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve) will make helping easier.

---

<div class="post-metadata">

**Author:** ![guybou](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@guybou](https://discourse.threejs.org/u/guybou)\
**Post date:** [February 5, 2018, 9:33am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/3 "2018-02-05T09:33:50Z")

</div>

I’m using it the same as in the pointerlock controls sample:  
[https://threejs.org/examples/?q=poin#misc\_controls\_pointerlock](https://threejs.org/examples/?q=poin#misc_controls_pointerlock)

but my camera required to be with z up:  
camera.up.set( 0, 0, 1 );

the controls is not working properly as it assume the camera has no rotation, see the pointerlockcontrols code:

```javascript
this.getDirection = function() {

	// assumes the camera itself is not rotated

	var direction = new THREE.Vector3( 0, 0, - 1 );
	var rotation = new THREE.Euler( 0, 0, 0, "YXZ" );

	return function( v ) {

		rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 );

		v.copy( direction ).applyEuler( rotation );

		return v;

	};

}();

```

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 5, 2018, 9:57am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/4 "2018-02-05T09:57:04Z")

</div>

I guess you have to change `PointerLockControls` so it meets your requirements. `PointerLockControls` is part of the examples not the core. User specific modifications to these files are a common thing.

---

<div class="post-metadata">

**Author:** ![guybou](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@guybou](https://discourse.threejs.org/u/guybou)\
**Post date:** [February 5, 2018, 10:49am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/5 "2018-02-05T10:49:45Z")

</div>

I know, I already tried…  
I’m asking for assistance to modify it, any idea?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 5, 2018, 11:55am UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/6 "2018-02-05T11:55:49Z")

</div>

Um, the controls work when i change the `up` vector of the camera in the mentioned example. As long as you don’t use `.lookAt()` everything should be fine…

May i ask, what are your reasons for changing the `up` vector of the camera?

---

<div class="post-metadata">

**Author:** ![guybou](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@guybou](https://discourse.threejs.org/u/guybou)\
**Post date:** [February 5, 2018, 12:57pm UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/7 "2018-02-05T12:57:05Z")

</div>

it’s a given requirement to use the z vector for height above ground

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 5, 2018, 1:32pm UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/8 "2018-02-05T13:32:55Z")

</div>

Have you considered to rotate the entire scene? Something like:

```javascript
scene.rotation.x = - Math.PI / 2;

```

---

<div class="post-metadata">

**Author:** ![obecerra](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/obecerra/32/12353_2.png) [@obecerra](https://discourse.threejs.org/u/obecerra)\
**Post date:** [July 23, 2020, 4:52pm UTC](https://discourse.threejs.org/t/pointerlock-with-camera-z-up/1770/9 "2020-07-23T16:52:57Z")

</div>

Hi I think I found out how to edit Pointer Lock Controls to work with z axis as up. I had to change the ordering of the euler var used and change the mouse movement x to affect the z component of the euler angle instead of the y component. Also I added new constraints to keep the camera from rotating 360 degrees in the vertical direction, however you can modify these by changing the MAX\_PI and MIN\_PI variables to suit your needs.

> <https://gist.github.com/obecerra3/2caf4abeb15bb56f1b54f857502c3209>
