The object3d.translateZ function in Three.js is resulting in unexpected NaN values for all position properties

I'm encountering an issue where the use of translate[X|Y|Z] on my object results in its position becoming distorted and only displaying NaN values.

Using Three.js r70

The relative position differs from the absolute position:

Snippet from my code

if (!this.following) return false;

var mesh = this.get(); //Single mesh
this.mesh.lookAt(this.mesh.worldToLocal((new THREE.Vector3(0, 0, 0)).setFromMatrixPosition(this.following.whom.matrixWorld))); //this.following.whom refers to another mesh

var followerPosition = mesh.localToWorld(new THREE.Vector3(0, 0, 0));
var followeePosition = this.following.whom.localToWorld(new THREE.Vector3(0, 0, 0));
var distance = followerPosition.distanceTo(followeePosition);

if (distance > this.following.distance) { //this.following.distance is a scalar value
    mesh.translateZ(distance * 0.02);
}

return true;

What could I be doing incorrectly? Is it not appropriate to use transformZ with relative values?

Answer №1

Upon further reflection, it appears that I overlooked a crucial detail. When the rotation of an object is NaN, the translation process will not succeed.

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

Implementing Jquery to Identify the Matching Indices of Two Arrays

I need to find the indices of similar values in array1 and array2, and then save them in a variable named stored_index. array1 = ["50","51","52","53","54","55","56","57","58","59"]; array2 = ["59","55","51"]; The desired result for stored_index is: sto ...

The npm outdated -g command is producing an error message that states "Unable to read the length property of undefined"

I am currently facing an issue while trying to check the version status of my npm installed global packages. When I run the command npm outdated -g --depth=0 in the terminal, I encounter the following error: npm ERR! Cannot read property 'length&apos ...

New update in Fullcalendar v2: Enhancements to dayRender function for agenda view and agenda

For the newest version of FullCalendar, I am in need of the dayRender callback to modify the color of disabled days. Unfortunately, this specific callback only functions for month, basicWeek, and basicDay views. However, I require this functionality for a ...

Previous Button on jQuery/Javascript Slider Not Functioning

Having a small issue with my previous button, #prev, as it is not scrolling back to the previous image but instead to the next image. This is the script I am using: http://jquery.malsup.com/cycle/int2.html Additionally, when I try to set the width of the ...

Tips for changing the background with a jquery slider

Using a jquery slider, I have a single layout with a center div for content. I am trying to change the color of the layout as I slide to a different page. This is for an ASP.NET MVC3 project. HTML: <div id="iPhone_Product"> <div class="s ...

Is the Await keyword failing to properly pause execution until the promise has been fulfilled?

I'm currently working on manipulating a variable within an async function, and I've noticed that the variable is being returned before the completion of the data.map function below. Even though I have the await keyword in place to pause the code ...

Utilizing AngularJS routes to load a specific URL when accessing a page for the first time

Working on developing a Single Page Application using AngularJS, my configuration settings appear as follows: app.config(["$routeProvider", function($routeProvider) { return $routeProvider .when("/", { redirectTo: " ...

The useEffect function is repeatedly making API calls within a component, despite not having any dependencies specified

As a newcomer to React.Js, I'm encountering an issue with useEffect repeatedly calling an API without any specified Dependency. Is there another approach I should consider? The relevant file is located at: /pages/dashboard/speaking/[slug].js } else i ...

Configuring the text box to utilize jQuery's datepicker feature

Currently, I am facing an issue with setting up a datepicker in a dynamic control creation scenario. The control is being created on the fly, causing inconsistencies with the id, which in turn is preventing the datepicker from functioning properly. Here is ...

Testing a Component Function in ReactJS: A Step-by-Step Guide

Testing methods in a Meteor application using mocha/chai can be done like this: describe('postMessage', () => { it('should add message', (done) => { // EXECUTE const messageId = postMessage.call({ articleId: 123, conten ...

Invoking a React function repeatedly (every second)

Currently, I am working with React and utilizing Material UI to create a modal. The modal is rendered as part of the body of the code, placed at the bottom of the page. Its visibility is controlled by the state; if it's open or closed. However, I&apos ...

Stop allowing the entry of zero after a minus sign

One of the features on our platform allows users to input a number that will be automatically converted to have a negative sign. However, we want to ensure that users are unable to manually add a negative sign themselves. We need to find a solution to pre ...

I am experiencing issues with launching chromium while running Puppeteer on Windows 11 using node js v19.4

Upon following the installation instructions in the documentation to install puppeteer with npm install puppeteer, I attempted to run the example for downloading a webpage as a PDF. However, every time I try to execute the code, Node.js returns the followi ...

Instead of logging the JSON file in the console, download it using $.getJson()

Is there a method to download a json file without using jQuery's $.getJSON() and having to log the callback function's argument? I would like to avoid manually typing it from the console.log due to its length. Is there an option to print it, eve ...

Refresh State component following fetch using Redux

Greetings everyone, I'm currently in the process of learning React and Redux. I've encountered a challenge where I am unable to update the state of a specific container using Redux without resorting to a setTimeOut function due to the asynchronou ...

When receiving a GET response after a server crash

Question: I am sending a Get request through Ajax every second and waiting for a response from the server. However, if my application crashes and I keep sending requests every second, I only receive a server timeout error (HTTP status code 502) with no oth ...

Showing text in a textarea while maintaining formatting (such as using <br>)

Can someone help me with formatting a block of text like this: hello <br> how is your day <br> 123 To look like this: hello how is your day 123 I also need to display it in a textarea field. I attempted to do so using the following code: $ ...

axios encountered a JSON parsing issue due to an unexpected character in the server's response

I'm encountering an issue with JSON parsing as I attempt to retrieve data from a server endpoint. This is the first instance where Axios is unable to automatically decode the JSON response. Upon inspecting my code, I noticed that Axios is detecting ...

Can text be replaced without using a selector?

I am utilizing a JavaScript library to change markdown into HTML code. If I insert <span id="printHello></span> within the markdown content, I can still access it using getElementById() after conversion. However, there is one scenario where th ...

Arranging a string array in JavaScript according to an integer array

Looking at the provided javascript arrays: letterArray ['a', 'e', 'i', 'o', 'u'] We also have another array that corresponds to it: valueArray [12, 22, 7, 7, 3] The goal is to sort the valueArray into: ...