The camera seems fixated on one object and refuses to transition to another even when the criteria are met, continuously alternating between the correct position and reverting back to

Currently, I am working on developing a universe using Three.js along with Leap Motion controls. However, I have encountered an issue where the camera position doesn't switch to different planets (adjusting camera position and lookAt) when swiping left or right. Instead, it consistently reverts back to the initial position set at the beginning of the code.

// Setting up camera position at the start of the webpage
camera = new THREE.PerspectiveCamera(25, $(window).width() / $(window).height(), 0.1, 100000);
camera.position.set(300, 300, 300);
camera.lookAt(scene.position);

Within my Leap Motion loop, I have added conditional statements for detecting left or right swipes:

if(frame.gestures.length > 0) {
       for (var i = 0; i < frame.gestures.length; i++) {
              var gesture = frame.gestures[i];

              if (gesture.type == "swipe") {
                   // Classifying swipe as horizontal or vertical
                  var isHorizontal = Math.abs(gesture.direction[0]) > Math.abs(gesture.direction[1]);
                  // Determining right-left or up-down swipe
                  if (isHorizontal){
                      if (gesture.direction[0] > 0) {
                         camera.position.set(300, 300, 300);
                         camera.lookAt(moonMesh.position);
                      }
                      else{
                          // Handle other cases here
                      }
              }
        }
  }

Just to clarify, I'm coding in JavaScript. Any suggestions on how to change the camera position and focus without it reverting back to the starting points would be greatly appreciated.

Thank you in advance,

Sincerely,
Tsukio Akira

Answer №1

Based on the code you provided, it seems that your focus is consistently set to moonMesh.position whenever a swipe occurs. Therefore, the object will always face the moonMesh and remain at the coordinates (300, 300, 300).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Acquire information from a JSON formatted string

I am having trouble extracting the first name from the JSON data provided below. While I am able to display the entire string using JavaScript [ alert(data); ], I am struggling to isolate just the first names. Any assistance would be greatly appreciated! ...

A guide to extracting the selected options from a multiple select box and presenting them in a text box

My goal is to have a dropdown menu displaying a list of items, each item corresponding to a specific price. When an item is selected, I want the total price to be automatically calculated and displayed in a textbox. Here is the code for my dropdown menu: ...

Executing NodeJS commands and Linux commands via Crontab scheduling

I have an EC2 AWS instance where various commands and scripts work perfectly, but do not execute within a crontab. The Crontab contains: 15 03 * * * pythonscript1.py 45 03 * * * pythonscript2.py 00 05 * * * gsjson 1z5OlqsyU5N2ze1JYHJssfe1LpKNvsr4j8TDGnvyu ...

Monitoring Selection Updates on Firefox for Android using JavaScript

I am in search of a method to monitor text selections on a webpage. I require code to run every time there is a change in selection. While I have successfully achieved this on the main desktop browsers, I am facing difficulties with Firefox for Android. I ...

How to Retrieve the Order Number of an Object in an Array using JavaScript ES6

Curious about JavaScript ES6 and needing assistance! I have a simple question - how can I determine the order number of an object in an array? [ { "pk": 23, "image": "http://localhost:8000/media/users/1/2_27.jpg"}, { "pk": 11, "image": "http://localho ...

Retrieve: proper authentication credentials were not provided

Whenever I make a request, everything works fine and I receive the data: const get_players = async()=>{ const response = await fetch('http://127.0.0.1:8000/player_stats/api/players/') const data = await response.json() console. ...

Guide on implementing a button in JavaScript React to toggle zoom and pan functionality for Leaflet maps

Looking to implement a button that toggles zoom and pan functionality for leaflet maps in JavaScript React. The challenge lies in achieving the desired effects on the map after creating the button. In my React project, I aim to switch a leaflet map betwee ...

Ways to manage properties that are non-existent

Whenever vm8 encounters a property that doesn't exist, it will display an error message like this: Cannot read property 'value' of null. For example, when passing an id that doesn't exist: var pass = document.getElementById('pass ...

Transferring data from one page to another using form variables

Currently, I have an existing app at . The app is designed to function on a single page, but I have been requested to convert it into a multi-page flow. Transitioning data from one page to another has proven to be challenging for me as I am more of a hobby ...

Struggling with implementing material-ui icons and facing a blank screen

Having trouble displaying material-ui icons on my website. Whenever I use them, a white screen appears. I have tried running the following commands: npm install @mui/material @emotion/react @emotion/styled npm install @material-ui/icons I also visited t ...

Is it possible to attach React Components to Elements without using JSX?

In my React Component, I have the following code: import React, { useEffect } from 'react' import styles from './_PhotoCollage.module.scss' import PhotoCard from '../PhotoCard' const PhotoCollage = ({ author }) => { let ...

When using the Chrome Inspector for JavaScript debugging, variables may appear as undefined in watches and the console, but they can still be inspected by

When I'm debugging AngularJS in Chrome inspector, I often encounter a frustrating situation. I know that certain variables are defined because I can hover my mouse over them in Chrome inspector and see them in the 'locals' tab. However, when ...

Migrating to Angular Universal for server-side rendering with an external API server

Thank you for taking the time to read my query. I have developed a project using server-side Node.js and client-side Angular 6. The purpose of the app is to provide information on cryptocurrency prices and details. I am now looking to transition my Angu ...

Obtain the data stored in an object within an array

I am attempting to retrieve the values of objects within an array. const bugSchema = new Schema({ title: { type: String, required: true }, comments:[ { user:{ type: String, required: true }, c ...

Linking to a Different Tab without Tab Mutation with Bootstrap 3.3.5

I am facing a similar issue to the mentioned questions. I am trying to use a link to change tabs, but the problem is that the link only changes the tab content and not the active tab. The most similar question can be found at: Bootstrap linking to a tab w ...

What are the steps to integrate Material-UI Tabs with react-router?

I've been working on integrating Material-UI tabs with routing in my project. Although the routing is functioning well and displaying the selected tab, the smooth animation while navigating between tabs seems to be broken. How can I ensure that react ...

retrieving attribute values from JSON objects using JavaScript

I am struggling to extract certain attribute values from a JSON output and use them as input for a function in JavaScript. I need assistance with this task! Below is the JSON data that I want to work with, specifically aiming to extract the filename valu ...

Cannot Get jQuery .flip() to Work Automatically Every 2 Seconds

There are 3 words that I want to rotate on their x-axis every 2 seconds (repeating). Using jQuery: $(function () { count = 0; wordsArray = ["Innovation", "Creativity", "Success"]; setInterval(function () { count++; $("#words").text(wordsArray[co ...

Using jQuery, we can replace all `<span>` elements with `<img>` elements and then verify if the images have been successfully loaded

Similar Inquiry: jQuery check if image is loaded I find myself in a scenario where the following HTML structure is utilized: <div class="image"> <img class="" src="content-images/1.jpg"> <span class="slide" rel="content-images/ ...

Unexpected outcomes arising from using nested arrays with jQuery validation plugin

I have been utilizing the jQuery validation plugin from . I am encountering an issue with validating a nested array "tax_percents[]" that is within another array. The validation seems to only work for the first value in the array, and even for the second f ...