Jump to content
  • Advertisement
Sign in to follow this  

Snowball Projectile Problem

This topic is 2076 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I am making a Christmas game for my school competition. My plan is to make a snowball fight but I ran into a problem with the snowballs.

I am using DirectX11, of which I know enough to make the game.


Once I have loaded the snowball mesh how do I:

Create them in the world - How do I create an object based on user input?
Specify their flight path - or do I do this at creation, as in their velocity.
Destroy them - Once they have hit the ground or the enemy.


Thanks in Advanced,

Share this post

Link to post
Share on other sites

Not sure how you create your snowballs(3D mesh? 2D sprite?). But in general, assuming you have arbitrary number of snowballs:

- When the game loads, create a single DX instance of the mesh/sprite(VB/IB/materials). Let's call this CSnowballMesh.

- On user input, create an instance of a different class called CSnowball and push it into a queue. It will look like this:

class CSnowball
      CSnowball(vec3 startPosition, vec3 direction, float velocity);
      void UpdatePosition(float fElapesedTime);
      vec3& getPosition();
      float mElapsedTime;
      vec3 mCurrentLocation; 

Then on each frame:

- Update all the snowballs position by calling UpdatePosition(). You can use the regular trajectory equations from mechanics to do that.

- For each snowball, run collision detection. If there was a hit, remove the snowball from the queue and delete it. Alternatively, if you have an animation of snowball hitting something, you can mark that the current object started its destruction sequence.

- For each object that remained in the queue, use the current position to create a world matrix, and dispatch a draw call of CSnowballMesh.


With this approach you consume minimum amount of GPU resources, while avoiding dynamic loading and get the flexibility to draw as many snowballs as you like.

There are a couple of optimizations possible - such as instancing - but the principal idea stays the same.

Edited by N.I.B.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!