Jump to content
  • Advertisement
Sign in to follow this  
DJTN

Trajectory / Matrices

This topic is 2210 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 have a collection of bullet particles. Each frame I update their position using a velocity vector. The bullets move from the camera (gun) outwards regardless of the movement of the camera which is correct, but when the camera moves -the bullets in the distance move with it, which is incorrect. They should continue on their trajectory (driven by their velocity) regardless of the camera’s movement.


I think the problem is the world transform matrix. It attaches a mesh and the particle emitter to the camera, however it also causes the bullets that have already been shot to move with the camera. The bullets should maintain their same trajectory after they’ve left.

Storing the world matrix for each particle is impractical but this gives you an idea of what I’m trying to accomplish. If each time a particle was added to the collection I stored the current world matrix then I could transform the particles position to maintain its trajectory. The question is - how I can I get the particles to maintain their trajectory without storing the world matrix for each particle?

Share this post


Link to post
Share on other sites
Advertisement
Why is a bullet particle system required to be attached to the camera? When the bullets start moving could you not just use the cameras current world position and direction as the starting point for the bullet movement? Sounds like they need to move free from the camera, so why attach them?
Otherwise, if they need to be attached, youll need to apply the inverse of the translations and rotations the camera does each frame to the bullets. If the camera strafes right along its right vector youd move the bullets to the negative right (left) the same amount, same with rotations, you rotate (pitch) down, apply an equal pitch up to the bullets to counter what the camera does.
They would still be attached, technically, but would appear to move free of the cameras movements. Edited by NumberXaero

Share this post


Link to post
Share on other sites
Sorry for the delayed reply, I was up late working.

Thanks for the input NumberXaero. This is not actually a gun and bullets its an effect for something else but it's easier to explain if I used this scenario to get my point (problem) across.

I have fixed the issue by transforming the start position by the matrix that attaches the emitter to the camera and then setting the velocity once, transforming it by the rotation matrix for the camera - and finally setting the world matrix to the emitter’s position before rendering.

I still have an issue with the yaw to iron out and clean the code up to be more efficient, but I'm happy with the solution.


Thanks again,
Dj

Share this post


Link to post
Share on other sites
Well now I’ve got another issue pertaining to the velocity. It’s changing incorrectly.

If I have a velocity vector (0, 0 ,10) and I do a matrix transform based off the rotations of the camera (pitch, roll, yaw), the velocity should always be pushing away from the camera. The problem is that the velocities Y is fluctuating up and down with the slightest change in the camera's pitch. Edited by DJTN

Share this post


Link to post
Share on other sites
I've solved my issue. For anyone else that finds this thread, the issue was in the matrix I was using to transform the velocity vector. To correct the matrix I created an inverted view matrix and manually changed element 41,42,43,14,24,34 to equal 0 and element 44 to equal 1.

This gave me the correct matrix to transform my velocity vector for anything attached to the camera (gun, flame thrower, etc...).


Hope this helps someone else.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!