Don't pay attention to the parent's rotation in THREE.JS

Currently, I am attempting to have a child object mimic its parent's position while maintaining its original rotation. I am concerned about performance, as I am already running 2 workers and have a large number of objects to manage. Is there a way to achieve this without impacting CPU usage significantly?

Is there a setting that would allow only the child's position to be affected, keeping its rotation unchanged?

It is crucial that when the parent is rotated, the child's position adjusts accordingly to maintain synchronization.

Answer №1

To stop a child object from rotating along with its parent's rotation, you can implement one of the following two methods, each with slightly different effects.

The first approach involves creating a new Three.js Gyroscope object:

var gyro = new THREE.Gyroscope();

scene.add(parent);
parent.add(gyro);
gyro.add(child); // attach child to the gyroscope

child.position.set(x, y, z);

The second method involves using an Object3D object:

object = new THREE.Object3D();
object.position.set(x, y, z); // set child's desired position relative to parent

scene.add(parent);
parent.add(object); // attach object to parent
scene.add(child); // attach child to the scene

If you opt for the second technique, you will need to manually update the child's position within the render loop, as shown below:

child.position.setFromMatrixPosition(object.matrixWorld);

Version used: three.js r.71

Answer №2

One alternative solution is to use the following code:

child.position.copy(object.position);

This is a different approach from WestLangley's suggestion, which is:

child.position.setFromMatrixPosition( object.matrixWorld );

I found that the latter method caused inaccuracies and jitter in the child's position.

Keep in mind that this response only addresses the first part of your question, specifically how to track the parent's position while maintaining the child's rotation.

If you could provide more details or clarification on the second part of your inquiry, it would be helpful in providing a more comprehensive answer.

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 Event Handlers Post-Infinite Scroll Refresh

I have incorporated the infinite scroll feature using a plugin that can be found at this website. This plugin helps in loading page content seamlessly. One jQuery event listener that I have set up is as follows: $('.like-action').on('click ...

Are you able to locate <td>s with identical classes using just a portion of the string?

There are multiple classes in the <td>s of my table. I am looking to identify each <td> that contains a specific string. For instance: <table> <tr> <td class="hello there">foo</td> <td class=" ...

Executing a javascript function using PHP

I'm experiencing an issue with a textbox that triggers a function on the 'onkeypress' event, causing the page to refresh each time the function is called. How can I resolve this using Ajax? <input style="height:39px; margin-bottom:10px" ...

Tips for effectively using $interval for ongoing polling in AngularJS?

Within my Angular codebase, I have implemented long polling functionality using the following code snippet: var request = function() { $http.post(url).then(function(res) { var shouldStop = handleData(res); if (!shouldStop()) { ...

Optimizing Animation Effects: Tips for Improving jQuery and CSS Transitions Performance

Wouldn't it be cool to have a magic line that follows your mouse as you navigate through the header menu? Take a look at this example: It works seamlessly and smoothly. I tried implementing a similar jQuery script myself, but it's not as smoot ...

Retrieve the image by its unique identifier while viewing a preview of the image before it is uploaded

Below is the script I am using to preview an image before it is uploaded. The HTML structure looks like this: <div> <img id="image" src="#"> </div> <input type="file" accept="image/gif, image/jpeg, image/png" onchange="readURL(th ...

How can I achieve unique spacing between rows in material-ui grid components?

What is the most effective method for creating spacing between specific rows in a grid using material-ui? Consider the following grid with spacing={0}: GridContainer row1 GridItem GridItem row2 GridItem GridItem row3 GridItem GridItem row4 Gr ...

Unable to update state in my React app when clicking on a button

There is a requirement for a button click to filter the job-card array by one specific category. For example, clicking on the button "Marketing" should only show jobs from the array that have the property "jobstags: Marketing". I followed a similar procedu ...

Resolving the issue of multiple instances of React within a single application

I'm currently working on a React module in my local environment. To link the module, I am using npm link. Although the module is being imported successfully, the hooks inside the module are failing with the following error message: Invalid hook call ...

Accessing the observable's value by subscribing to it

There is a defined observable called imageOptions$ in my code: imageOptions$: Observable<BoundImagesToProject[]> = this.imagesService .getBoundImages({ projectId: this.projectId }) .pipe(map((images) => (images.data))); and it is used in the temp ...

Submit the form without displaying any output in the browser, not even in the view source code

I have a basic form that needs to be submitted multiple times, but I want the submission process to be hidden from the browser. Simply using "hidden" or "display:none" won't completely hide the form code when viewing the page source. I tried using PHP ...

XPath Selector in Puppeteer version 22.x

Despite poring over the latest Puppeteer v22.x documentation on XPath, I am still struggling to grasp how to effectively utilize XPath in Puppeteer 22.x. My goal is to click on an element that contains the text 'Next'. Here's the HTML snipp ...

Serve static assets files based on the route path instead of using absolute paths

Within Express, I have set up the following route: app.get('/story/:username', function(req, res){ res.render('dashboard.ejs'); }); Prior to that, I am serving any static files located in /public: app.use(express.static(__dirname ...

The undead browser refuses to display a window upon attempting to open using the open function

tools first attempt Darwin 14.3.0 Darwin Kernel Version 14.3.0 io.js v1.8.1 zombie Version 4.0.7 released on April 10, 2015 second attempt Linux ubuntuG5 3.13.0-48-powerpc64-smp node.js v0.10.38 zombie Version 3.1.0 released on March 15, 2015 comman ...

"findByIdAndUpdate continues to work successfully even when the request body includes parameters that are not defined in

Referenced from This particular tutorial on MERN stack development... In my mongoose schema, I have defined 4 fields: const mongoose = require('mongoose'); const Schema = mongoose.Schema; let Todo = new Schema({ name: { type: String ...

React error #425: Timezone formatting causing minification issue

Encountering a strange issue that seems to only occur on Vercel. The error message reads: Uncaught Error: Minified React error #425; visit https://reactjs.org/docs/error-decoder.html?invariant=425 for the full message or use the non-minified dev environme ...

Guide to sending and receiving JSON data using XAMPP PHP

Currently, my XAMPP 7.1.10-0 server is up and running with the following index.php file: <?php if(isset($_POST["username"])) { echo $_POST; header("Location:getbooks.php"); exit; } else { echo file_get_conten ...

Generate interactive tables using data from an XML file

Hello, I'm in the process of generating tables from an XML file using Node.js with the Express framework. I am utilizing npm modules xmldom and xmldoc for this task. The objective is to present these data tables on an ejs page. Here is the structure ...

I am looking to extract a specific value from my JSON file

I need to extract specific values from a JSON file. For example, if the JSON file contains id, name, and lastname, I am interested in extracting the id value. fs.readFile("user.json", function (err, data) { if (err) throw err; console.log(data. ...

Confirm Submission Issue in HTML Form

During my testing of the blacklist confirmation dialog, I encountered an issue where clicking the OK button did not submit the form as expected. Instead, it seemed to be stuck in a loop where clicking the button had no effect and the dialog remained on scr ...