Repositioning singular particles within a Three.JS particle array

Having an issue with my Three.js project. I've been working on a particle system and trying to animate particles as the frames are rendered. However, I'm running into a problem where the particles aren't moving at all. The code snippet I used as reference is from , which uses particle.position.y. But when I tried changing my code to match that syntax, the JS console throws an error saying

Cannot set property 'y' of undefined
. Any guidance or suggestions would be greatly appreciated.

Here's the full source code:

        var scene, camera, renderer, particleCount = 0, particleSystem, particles;

        init();
        animate();

        function init()
        {
            scene = new THREE.Scene();
            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            scene.add(camera);
            camera.position.z = 5;

            renderer = new THREE.WebGLRenderer();
            renderer.setSize(window.innerWidth, window.innerHeight);
            document.body.appendChild(renderer.domElement);

            particleCount = 1800,
            particles = new THREE.Geometry();
            var pMaterial = new THREE.ParticleBasicMaterial({color: 0xFFFFFF, size: 0.5});

            for (var i = 0; i < particleCount; i++)
            {
                var pX = Math.random() * 500 - 250,
                    pY = Math.random() * 500 - 250,
                    pZ = Math.random() * 500 - 250,
                    particle = new THREE.Vector3(pX, pY, pZ);

                particles.vertices.push(particle);
            }

            particleSystem = new THREE.ParticleSystem(particles, pMaterial);
            scene.add(particleSystem);
        }

        function animate()
        {
            requestAnimationFrame(animate);
            renderer.render(scene, camera);

            var pCount = particleCount;
            while (pCount--)
            {
                var particle = particles.vertices[pCount];
                particle.y = Math.random() * 500 - 250;
                particleSystem.geometry.vertices.needsUpdate = true;
            }

        }

Answer ā„–1

To ensure proper functionality, make sure to include

particleSystem.sortParticles = true;
immediately after initializing your particleSystem.

Answer ā„–2

Having faced the identical problem in a tutorial with ThreeJS 86, I found that I did not need to use setY() or

particleSystem.sortParticles = true;
. Instead, using
particleSystem.geometry.verticesNeedUpdate = true;
worked for me (not
particleSystem.geometry.vertices.needsUpdate = true;
).

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 we dynamically reference past elements in an array without using indices like "i-1", "i-2", and so on?

function play_tune(melody) { let played_notes = []; let durations = []; let positions = []; let wait_time = 0; let time_passed = 0; console.log("Melody initiation.") for (let key in melody) { played_notes.push(melody[key].note); dur ...

The callback function in AngularJS filters

I'm currently using an AngularJS filter to sort through a list of items. Here is the Jade markup I am using: li(ng-repeat="parcel in parcels | filter : filterActiveAreaParcels") After the filter function runs and the elements are displayed in the DO ...

How can the background color of a DIV be altered based on the values of an array's minimum

Basically, I am fetching values from an array using AJAX. The background color will change from green to red based on the "aht_value". Currently, the colors are displaying correctly because I hardcoded the values in the calculation below. However, I want t ...

Ensuring session data is updated when saving a mongoose model

I am facing a challenge with updating express session data in the mongoose save callback. Is there a way to access and modify the session data from within line 4 of the code? app.get('/', function(req, res){ var newModel = new Model(somedata); ...

retrieve the value of a specific key from an array

How can I extract key-value pairs from an array in JavaScript where the data is structured like this? jsonData = [ {"dimensions":[5.9,3.9,4.4,3.1,4.8],"icon":0,"curves": [false,false,false,false,false],"id":"p1","color":"0x000000"}, {"dimensio ...

The synergy between ES6 arrow functions and array mapping techniques

I'm currently exploring shorthand methods of writing ES6 code and I've come across an example that has left me puzzled. The last shorthand used, "({length})", retrieves the length property of an array. While I understand how it works in this cont ...

Having trouble extracting the Top-Level Domain from a URL

I'm struggling to find a reliable way to extract the Top-Level Domain from a URL. The challenge I'm facing is that the URLs entered by users can vary greatly - they might enter www.google.com, m.google.com, m.google.uk, google.uk, or www.m.google ...

Is it possible to dictate a custom sequence of operations in THREE.js?

Check out this question on Stack Overflow regarding Threejs Transform Matrix ordering: Threejs Transform Matrix ordering I'm currently working on depicting the orbits of planets and I've encountered some difficulties when trying to change the in ...

Apply a specific class to the data retrieved from MongoDB in a Meteor application depending on a field value in the database

In my Mongo collection documents, I have an array containing various objects for a chat app. When I try to display the data, I encounter an issue where all messages are getting the "my-message" class instead of just my messages. I'm struggling to tar ...

Tips on resolving the issue of an Axios post request not appearing in a get request in React

When using axios to make a post request in this code, a new username is posted, but there is an issue with retrieving the posted name from the API. How can I fix this problem to view my posted request? const App = () => { const [data, setData] = u ...

The 'openNewWin' property does not hold a valid Function object and is either null or undefined

I am currently working with an asp menu and trying to configure the navigateurl so that it opens in a new popup window. The issue I am facing is that when I execute the code, I encounter the following error: Error: The value of the property 'openNewW ...

Incorporating a static background image slideshow in ASP.NET - a step-by-step guide

I am currently working on my asp.net website and I would like to incorporate an image slideshow as the background of my homepage. This idea was inspired by a site I came across, . I have successfully implemented the slideshow, but now I am wondering if it ...

Is the AJAX function failing to execute? Potential issue with the database connection?

I am currently working on setting up my project on the localhost. I've encountered an issue with the built-in ajax function upon success. Below is the snippet of the javascript function in question: function fetchResults(page, searchString) { page ...

What causes the Angular child component (navbar) to no longer refresh the view after a route change?

Hello everyone, I'm excited to ask my first question here. Currently, I am working on developing a social network using the MEAN stack and socket.io. One of the challenges I am facing is displaying the number of unread notifications and messages next ...

Enhance the appearance of the initial division in the Bootstrap slider by incorporating an additional class using PHP with ACF (Advanced Custom Fields

I am attempting to create a bootstrap slider using an ACF repeater field with 3 slider images. Below is the code I am currently using: <?php if( have_rows('text_block_repeater') ): ?> <div id="carouselExampleControls" class= ...

Executing Controller Actions within a JavaScript Timer

Presenting my latest timer: var eventDate = new Date(Date.parse(new Date) + 3600); function countdown() { var elapsed = Date.parse(eventDate) - Date.parse(new Date()); var seconds = Math.floor((elaps ...

The route param is throwing a "Cannot read property 'name' of undefined" error, indicating that the property

Currently, I am enrolled in an ExpressJS course on TUTS+ From the video tutorial, I have implemented the following code snippet (excerpt from video): var express = require('express'), app = express(); app.get('/name/:name', funct ...

Leveraging d3.js for Visualizations in an Angular2/Node/Express/MongoDB Application

Iā€™m working on integrating d3.js (https://www.npmjs.com/package/d3) into my project, and upon loading the page, I encounter a ZoneAwareError. After executing npm install d3 --save, all dependencies were successfully installed. Although I followed the gui ...

What is the best way to implement restful instead of query syntax in a $resource factory?

Recently, I set up a $resource factory like this: (function() { 'use strict'; app.factory('WidgetFactory', [ '$resource', function($resource) { return $resource('http://localhost:8282/widget/:widgetId&apo ...

Express-session is failing to return a value in spite of my explicit declaration of the session

I've been working on my website for quite some time and everything was smooth sailing, until now. Here's the issue: after a user logs in, a session cookie named "user" is created to store their email. Upon console logging the cookie right after ...