Creating a barrier between objects in motion

I need assistance with creating a connection between two dynamic vertices in my project. The information for each vertex is stored within an object named object, containing the position data as a THREE.Vector3.

To create the line connecting these vertices, I used the following code:

var Line = function(scene, source, target){
  var geometry = new THREE.Geometry();
  geometry.dynamic = true;
  geometry.vertices.push(source.object.position);
  geometry.vertices.push(target.object.position);
  geometry.verticesNeedUpdate = true;

  var material = new THREE.LineBasicMaterial({ color: 0x000000 });
  var line = new THREE.Line( geometry, material );

  scene.add(line);
  return line;
};

The positions of the vertices are updated using the following code snippet:

vertex.object.position.add(vertex.velocity);

I attempted to link the line's points to the corresponding vertices by assigning source.object.position and target.object.position to line.geometry.vertices[0] and line.geometry.vertices[1]. However, the connections between the vertices and lines seem to be inaccurate. Despite the vertices moving correctly, the lines do not align properly.

How can I ensure that the lines move accurately along with the vertices?

Answer №1

Remember to update the vertices in your animation loop by setting

line.geometry.verticesNeedUpdate = true
. This is important because after rendering, it automatically becomes false. Check out this jsfiddle example for reference.

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

How can I use Vue to close the side Navbar by targeting the body tag and clicking anywhere on the screen?

I am looking to make a change in the Navbar position by moving it right: -500px (to close the navbar) when clicking anywhere on the window. In HTML and JS, I can achieve this by targeting the body tag. How can I accomplish this in Vue? I already have funct ...

Tips for resolving the UNABLE_TO_GET_ISSUER_CERT_LOCALLY issue while attempting to install Sentry using npm or curl

https://i.stack.imgur.com/G8hfZ.png curl -sL -k https://sentry.io/get-cli/ | bash Even though I've specified not to verify the certificate with -k, I'm still facing issues trying to install it. The script is supposed to automatically install sen ...

Dynamic loading of tinymce in progress

When tinymce is loaded in the head and before dom, everything works fine. However, if I attempt to load the JavaScript with ajax using jquery.getScript(), it doesn't work. I initialize tinymce when the user clicks the content area, so the dom must be ...

Iterating over a JSON object with an embedded index in Angular using ng-repeat

Here is the structure of a JSON object: { "0": { "Order_Id": "100000001", "prodct_Status": "Pending", "Price": "8.0000", "date_created": "Jun 4, 2014 7:55:42 AM", "Shipping_Address": "vbccv", "Region": ...

React: Modifying a single input field out of many

Can someone please review this code snippet: https://stackblitz.com/edit/react-koqfzp?file=src/Section.js Whenever I add an item, a random number is also added that I want to be able to edit. This number is displayed in a Material UI Text Field component. ...

Can one iterate over a JavaScript object using forEach() even if the keys are undefined?

During a code review, I came across the following code: var a = { ... }; // an object filled with key-value pairs for (var key in a) { if (!angular.isUndefined(key)) { do.stuff(); } } I am questioning whether key can ever be undefined or ...

"Master the art of implementing a slide toggle effect with jQuery UI using

Looking to implement the jQuery UI slide toggle functionality in plain JavaScript... <center> <button id="button" class="myButton">Read More</button> </center> <div id="myDiv"> <p>Cool Read More Content Here. Lorem Ips ...

Switching players every two turns in a JavaScript AngularJS game

I have implemented an AngularJS score keeping game where players switch every two turns. The code works for one round, but I want to create a loop that keeps switching players. Check out my code below: app.controller('EventController', function( ...

What is the best way to adjust my content to be mobile-friendly with the Material UI drawer?

I am facing an issue with adjusting the content in Form.jsx based on the movement of the drawer. When I expand the Drawer by clicking on the menu icon, the content inside the body does not move along with it. How can I make sure that the content moves acco ...

Error message in Jquery function: Uncaught TypeError - undefined property 'noDisagree'

Hey there! I am attempting to invoke a function in an AngularJs controller with a parameter using Jquery, but unfortunately encountering the error: Uncaught TypeError: Cannot read property 'noDisagree' of undefined function noDisagree(id){ ...

Enhance your Wordpress posts with a custom pop-up form for each individual button

On a page, there are various custom posts being displayed with the post type 'property', each containing a button: <button class="btn btn-primary">Submit Offer</button> This button is looped and shown below every post. What ...

The inRequestScope feature seems to be malfunctioning and is not functioning as intended

Need help with using inRequestScope in inversifyJS For example: container.bind<ITransactionManager>(Types.MysqlTransactionManager).to(MysqlTransactionManager).inRequestScope() ... container.get<ITransactionManager>(Types.MysqlTransactionMana ...

Encountering an issue with googleapis in Vue.js: Error - The argument labeled as "original" must be of type Function

Attempting to retrieve rows from a Google Spreadsheet using googleapis for a Vue project. I have set up the necessary project and service account credentials in the Google console. However, upon clicking the button, I encounter this error: TypeError: The " ...

Troubleshoot: Trouble with selecting the clicked item in AngularJS when using ng-repeat

Is there a way to only delete the selected item from my ng-repeat list instead of deleting all items at once? I can currently delete all items using ng-repeat, but I want to be able to delete just the clicked item. How can I achieve this? https://i.stack. ...

Challenges arise when integrating PHP variables into JSON

I am facing an issue with the following JSON code: $dataB = <<<DATA { "actualArrivalDateTime":"2021-09-07T10:00", "containerNumber:" "000", "shipmentNumber": aaaa1, "co ...

Utilizing Vue CLI plugin to dynamically pass JS variables as props

I am currently using version 4.5 of the Vue CLI plugin. I have created a component that takes in a title as a prop. This component has been converted into a web component and added to an HTML webpage (which is not a Vue JS project) Now, I am attempting to ...

Stop the user from navigating away from the current page if any changes have not been saved, all within React without relying on

My project includes a panel that opens as a modal from right to left. This panel contains a left navigation menu with various options that, when clicked, display different components. These components primarily consist of forms, and my goal is to alert th ...

I'm encountering a CastError while attempting to delete data in mongodb using Id

Encountered an issue while attempting to delete a MongoDB entry using the 'findByIdAndRemove' function in Mongoose. Specifically, it is throwing a 'Cast to ObjectId failed for value error'. Delete Service routes.delete('/:id' ...

Conceal the Navbar in React js when the user is in the dashboard

I am currently working on my collage project and I need to find a way to hide the navigation bar if the user is in either the admin, employee, or publisher dashboard. This means that the navbar should be hidden when the user is on the paths: /admin, /emplo ...

The caret operator in NPM does not automatically install the latest minor version of a package

Within my package.json file, one of the dependencies listed is labeled as... "@packageXXX": "^0.7.0", Upon running the "npm outdated" command, I observed that... @packageXXX current: 0.7.0 wanted: 0.7.0 latest: 0.8.0 Despite executing "npm ...