• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
PaCkEtPiRaTe

Trouble with movement vector of particles.

3 posts in this topic

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.

Edited by PaCkEtPiRaTe
0

Share this post


Link to post
Share on other sites


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)

 

 

0

Share this post


Link to post
Share on other sites

 


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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0