This past weekend I had some free time and wanted to start work on a projectile/weapon system for my project, some of the threads on this forum gave some inspiration how to make lasers. I was pretty thrilled with how it came out, so I threw together a short test video to share…can download it here:
http://www.mediafire.com/download.php?ednlmyucw2d
The laser pulses are trailmeshes (no bloom, but I haven’t experimented with any post-processing effects yet). I’ve been fiddling around with other ways of making lasers, but this one (so far) came out the best looking. Still have to implement collision handling, so I can get some explosions going, and ultimately destroy enemies and such… The game is intended to be an overhead space shooter, a la Subspace/Continuum, although I relaxed the chase camera in order to get some nice shots ;).
looks very cool, nice sound effects also
real cool… the corellian corvet model also looks nice… very nice work. I will pick your brain at one point on how you did this
Mindgamer said:
real cool... the corellian corvet model also looks nice... very nice work. I will pick your brain at one point on how you did this :D
The corvette was a free model, but nonetheless very cool ;)
As far as the projectile is, I tried a few methods out (ie billboard quad, a billboard quad + trailmesh to achieve a roundish plasma burst that would have a narrower trail --- a la Empire at War, though I kept getting a significant gap between the two). So far trailmesh gave the best results, here's the gist of what the projectile does.
The projectile knows:
1) Its origin + velocity; velocity also has the direction (normalized), which is fed in either as the world rotation of the starfighter, or the world translation of the starfighter (as a target for the corvette). Then the velocity is scaled up either by the current speed of the craft (ie the starfighter) or a default speed (ie the corvette, which for this scenario doesn't have a speed, and the lasers aren't even forward firing). So it can have two different behaviors, but both are tied together as they should only travel in a straight line once released.
2) TrailMesh was largely grabbed from the test code in the source, however I turned down the trail sections to 5. Although I created my own texture for it ;)
3) Update appropiately/use something similar to a timed life controller to give it a life span then remove from the scene.
Other projectiles of course can be different, ie a missile that should follow a target would also hold the target.
I mostly pieced this together from a lot of ideas on the boards, although this is more than just making the projectile, I've also made a weapon system where I can attach a weapon node to a starfighter as a sort of projectile emitter.
Edit: although this also seems imperfect, as there are two or three spots in the video where the bolts seem to re-orient when the camera shifts a certain way. I'm not sure if thats me or if that's really happening, thats why I tried and get a lot of different angle shots to make sure they were purely straight line (at least for now, you can possibly implement an inaccuracy factor to make some bolts veer off a bit, as they can get a bit repetitive in some of the video shots*)
*I wonder if a lot of this is doable with the particle system, I've tried it without much success of getting a good looking laser with it. I've been digging into some of the material files in Empire At War, and I was impressed with how their turbo lasers were made, they were particle effects of single quads with a red orb, where you could tack on a tail of variable length, and also animate in either a continuous particle stream (ie a real laser) or in a burst fire mode. Very cool stuff, and by large some of their billboarding (the planets were billboarded!) certainly gave some ideas.
Looks really nice.
You think you could give u a single player version of that demo as a game?
I read you are doiing a massive online scifi game but the only thing I'd like to do is blow some rebel ships to pieces
Starnick said:
Thanks for the description, I appreciate it. I have been slowly contemplating myself how to make a good long laser burst that would still look realistic... ie - go to infinity when it misses the target, not stop at the target's distance. Only thing I can think of is pre-determining the hit/miss and just rendering the correct laser line...
However if I want the laser line to last a while... sort of strafe across the target and then when it stops hitting the target, fly off into distance, its a bit trickier. I think what you described 'Empire At War' does might be a good solution... as long as good looks can be achieved with the particle system.
Mindgamer said:
Starnick said:
Thanks for the description, I appreciate it. I have been slowly contemplating myself how to make a good long laser burst that would still look realistic... ie - go to infinity when it misses the target, not stop at the target's distance. Only thing I can think of is pre-determining the hit/miss and just rendering the correct laser line...
However if I want the laser line to last a while... sort of strafe across the target and then when it stops hitting the target, fly off into distance, its a bit trickier. I think what you described 'Empire At War' does might be a good solution... as long as good looks can be achieved with the particle system.
In one of the many laser threads out there, someone implemented a "real" laser and used a quad between the origin and the destination and stretched it out, I'm pretty sure I remember you posting in that thread (or posted the thread? lol). That looks pretty good, and with some extra work would sound like what you were saying.
As for the EAW thing, it would be great if I could mimic it with our particle system...the tail is the only tricky part of that.
I have bit of a question, in regards to the 3d math here. As you can see from the video, the corvette fires in the direction of the starfighter, but not really at it - if the starfighter was stationary, none of the laser bolts would actually hit the starfighter.
So the idea here is, given some arbitrary source and target point, I want to calculate the direction that the projectile would have to take to intercept with the target point, traveling across a static linear path from the source point.
In this example, it would be the weapon node’s world translation as the origin and the world translation of the starfighter node. If the weapon node is positioned at at 0,0,0 in 3d Space, of course the projectile acts as it should and intersects the starfighter. But this is not always the case, as a weapon node could be positioned anywhere relative to its parent (e.g the corvette), so it would appear I’m missing something, or perhaps not doing my calculations correctly?
Can anyone give some insight? My gut feeling is that I’m missing something really easy…
I feel stupid
Just subtract the position of the source from the position of the target, to get the relative position.
Then normalize the relative position to get the direction vector from source to target.
If you want to allow for a moving target then just assume the target is a bit further ahead than it actually is.
Or you could calculate the exact point, but then it might not follow a linear path
Alric said:
Just subtract the position of the source from the position of the target, to get the relative position.
Then normalize the relative position to get the direction vector from source to target.
If you want to allow for a moving target then just assume the target is a bit further ahead than it actually is.
Or you could calculate the exact point, but then it might not follow a linear path :)
There are times when I really want to strangle my computer. I did try that, thinking it was the right thing to do...and it didn't work! (Therefore, the doubting of mathematical abilities commenced!)
Thanks for the validation though, because that got me thinking, and I put that calculation directly into the weapon node object...and it worked. :?
Originally, in my spaceship object (e.g. the corvette), when I ask it to fire its weapon, it calculates the direction from the translation of the weapon nodes attached to the spaceship object and the translation of the target, then that gets sent to the weapon object, which normalizes the direction vector when it creates a projectile, which is then multiplied with whatever speed the projectile should start out as, thus acting as its velocity. For each update, the projectile multiplies the time between frames with each component, and adds them to a translation vector.
So somewhere along that line, something got messed up, though I'm not exactly sure where... :|
Code's starting to get a bit messy now...but I knew it was something simple. Thanks.