Jump to content

  • Log In with Google      Sign In   
  • Create Account


Trouble with movement vector of particles.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 PaCkEtPiRaTe   Members   -  Reputation: 104

Like
0Likes
Like

Posted 09 August 2013 - 05:36 PM

I'm having some trouble with the weapons I'm implementing in my game. At first I didn't notice the problem because I was emitting so many of them, it seemed to be working as expected... but when I added a cooldown to a new weapon I made, I noticed that all the particles were bunching together and traveling on the same angle. I'm honestly not sure what the problem is, because I've used console printouts to see what the data is, and it all seems to be fine.

 

Here is the Github project with all the code. The relevant files will be listed below.

http://www.github.com/packetpirate/Generic-Zombie-Shooter

 

Relevant Files (as far as I know):

  • genericzombieshooter.structures.Particle
  • genericzombieshooter.structures.weapons.Shotgun (same problem with Flamethrower)

I'm not positive that the problem lies in those files, but I'm almost sure that the problem is within one of these methods.

 

Particle class:

  • constructor
  • update() method

Shotgun/Flamethrower classes:

  • fire() method
  • updateWeapon() method

 

Obviously, it's a large project, so I expect questions, so let me know if you need more information, because I just don't know where to look for the problem. I'm pretty sure it has something to do with moving them, but like I said, there's no guarantee. Also, these are some anomalies I noted while playing around:

  • Obviously, the biggest problem is that the particles "bunch together" and move along the same angle. The idea for moving them was to give them a "spread" value, which is then multiplied by a random double (0.0 - 1.0) to get a random value between 0 and the PARTICLE_SPREAD value. Then this is multiplied by -1 if the "mod" variable is true, so it can go either PARTICLE_SPREAD or -PARTICLE_SPREAD degrees away from the origin angle. This value is then added to the theta stored within the Particle object. To move the particle, I simply got the sin of the X value of the position variable and the cos of the Y value and multiplied them by the speed, then added them to the current position. I've used this too many times to think there's something wrong with it.
  • When the particle creation is reduced to a single particle (for loop commented out) and the values kept the same, the particles move extremely slow compared to while it's in the loop, almost as if the number of iterations has some bearing on the speed... but the speed provided is a literal value. I used an iterator to iterate over the particles when updating them, and I was wondering if for some strange reason, only one particle is being updated multiple times.

There may be other anomalies I'm not aware of. Any help is appreciated!

 

P.S. Image is not of the problem... just thought I'd attach a screenshot for you to look at.

Attached Thumbnails

  • generic-zombie-shooter_16.png

Edited by PaCkEtPiRaTe, 09 August 2013 - 05:37 PM.


Sponsor:

#2 Norman Barrows   Crossbones+   -  Reputation: 1849

Like
0Likes
Like

Posted 09 August 2013 - 06:48 PM


To move the particle, I simply got the sin of the X value of the position variable and the cos of the Y value and multiplied them by the speed, then added them to the current position.

 

that should be the particle's unit direction vector's projections onto the x,y axes, not the x,y coordinates of the particle, multiplied by the speed, then added to x and y respectively:

 

x+=x_projection(direction_unit_vector)*speed

y+=y_projection(direction_unit_vector)*speed

 

where:

 

x_projection=magnitude_of vector*sin(theta)         

y_projection=magnitude_of vector*cos(theta)

 

and 

 

theta is the angle from the up axis (postive y) to the particle's direction of travel.

 

if your positive y axis points down, you'll need to adjust accordingly.

 

this reduces to:

 

x+=speed*sin(theta)       // theta is the current heading of the particle, expressed as a rotation in degrees or radians, clockwise from the up axis

y+=speed*cos(theta)

 

or in a left hand 3d coordinate system:

 

x+=speed*sin(yrot)       

z+=speed*sin(yrot)       

 

 

what you've described is:  

 

x+=speed*sin(x),

 

not:

 

x+=speed*sin(current_heading)

 

 


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#3 PaCkEtPiRaTe   Members   -  Reputation: 104

Like
0Likes
Like

Posted 09 August 2013 - 07:26 PM

 


To move the particle, I simply got the sin of the X value of the position variable and the cos of the Y value and multiplied them by the speed, then added them to the current position.

 

that should be the particle's unit direction vector's projections onto the x,y axes, not the x,y coordinates of the particle, multiplied by the speed, then added to x and y respectively:

 

x+=x_projection(direction_unit_vector)*speed

y+=y_projection(direction_unit_vector)*speed

 

where:

 

x_projection=magnitude_of vector*sin(theta)         

y_projection=magnitude_of vector*cos(theta)

 

and 

 

theta is the angle from the up axis (postive y) to the particle's direction of travel.

 

if your positive y axis points down, you'll need to adjust accordingly.

 

this reduces to:

 

x+=speed*sin(theta)       // theta is the current heading of the particle, expressed as a rotation in degrees or radians, clockwise from the up axis

y+=speed*cos(theta)

 

or in a left hand 3d coordinate system:

 

x+=speed*sin(yrot)       

z+=speed*sin(yrot)       

 

 

what you've described is:  

 

x+=speed*sin(x),

 

not:

 

x+=speed*sin(current_heading)

 

 

But x += speed * sin(theta); and y += speed * cos(theta); IS what I'm doing. I'm not quite sure what you mean. It still moves on the angle I give it... but ALL the particles in the group move on the same theta, rather than the theta that was generated when the Particle was created, and I have no idea why.



#4 PaCkEtPiRaTe   Members   -  Reputation: 104

Like
0Likes
Like

Posted 09 August 2013 - 09:26 PM

Ok, Reddit was able to answer my question. The problem had absolutely nothing to do with the formulae, and was actually being caused by the fact that all particles created in groups were sharing the same Point2D object because I forgot that Java passed objects by reference... so all I had to do was create a new Point2D object from the other one and use that. I feel like a bonehead.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS