Skip to content

Commit

Permalink
fix: initial camera position in keyboard controls (#119)
Browse files Browse the repository at this point in the history
* fix: initial camera position in keyboard controls

* fix: watch camera on initial keyboardControl
  • Loading branch information
JaimeTorrealba authored Jul 8, 2023
1 parent 2d4e37c commit e4a03a6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/controls/KeyboardControls.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, shallowRef } from 'vue'
import { ref, shallowRef, watch } from 'vue'
import { useRenderLoop } from '@tresjs/core'
import { PointerLockControls } from 'three-stdlib'
import { onKeyStroke } from '@vueuse/core'
Expand Down Expand Up @@ -93,8 +93,8 @@ const {
is2D = false,
} = defineProps<KeyboardControlsProps>()
const { state } = useCientos()
const initCameraPos: number = state?.camera?.position.y || 0
const xMove = ref(0)
const zMove = ref(0)
const isHeadBobbing = ref(false)
Expand All @@ -105,6 +105,11 @@ const HBAmplitude = 0.3
const initJumpTime = ref(0)
const wrapperRef = shallowRef()
const _forward = is2D ? 'y' : 'z'
let initCameraPos = 0
watch(() => state.camera, () => {
initCameraPos = state.camera?.position?.y || 0
})
// FORWARD DIRECTION MOVEMENTS
onKeyStroke(
Expand Down

0 comments on commit e4a03a6

Please sign in to comment.