Today I spent 3 nice hours in the autumn sunshine riding motocross at Uringe which is about a 45 minute drive from where I live. When I came home I first had to wash the bike, then I had to wash my Enduro bike that I had left in the garage all muddy the week before. Since the gear was out I also decided to wash my car.
It was 5:15 PM by the time I got in and we then headed straight to the playground with my son so he could play for a couple of hours. Back at 7:15 PM. Then it was time for him and my daughter to go to sleep so after changing into PJs, the nightly bottle, brushing teeth, saying good night, getting them a sleep, it was 9:00 PM.
Still no development as it was time for me and my wife to eat. I made some fanjitas, or was it burritos, and by the time they were done and we'd finished eating it was 10 PM.
Finally, I'm really tired but I launched Unity to get some more development done.
Didn't get a huge amount done today during the 3 hours I could spend developing (10 PM - 1 AM) but some progress was made.
Missiles on the way
I'm adding support for missile and currently I can fire missiles with smoke trails. Since the trail needs to live longer than the missile (if the missile reaches end of life or impacts) I detach the smoke trail particle system gameObject from the parent missile gameObject so it can fade away nicely.
I also added parent velocity from the ship that fires a bullet/missile but even though it is correct to do so in real life it didn't feel right in the game. Ok, it's fine if you go straight ahead because if you add the velocity of the spaceship the bullet will move away from my spaceship at the same rate as it would have if the spaceship was stationary... BUT... since the spaceship has drag (funny in space, huh?) and the bullets/missiles do not it looked very peculiar so I'm opting to add part of the parent velocity to my bullets/missiles.
The problem with this partial velocity I need is that I don't know how to calculate it so I had to spend some time drawing a picture and posted a question
about it in the Unity3D forums.
Should I treat missiles like bullets?
I've also been faced with some other issues today. For simplicity, should I treat missiles like bullets or should they have a separate class?
The benefit of sharing the same class, even if the name is "Bullet", I would reduce the complexity as anything fired from a weapon is an instance of the bullet class. Another benefit is that they can share properties, so a bullet could become homing if I ever wanted to add that as a feature.
The downside of treating it as a bullet is that I have to do a lot of checking in the code to handle missile-like specific properties, such as a smoke trail, acceleration, homing, etc.
My decision, for now, is to treat it as a bullet. I'll also keep it as a raycast and move it by changing it's position every frame rather than treating it as a rigid body with it's own thruster and physics properties.
Homing missiles might become a networking issue
Firing projectiles and rockets in a straight line is not a big deal with a network game. The server tells all the clients that a bullet was fired at X,Y with a velocity of Speed. All the clients can then instantiate their own bullets and there is no need for the server to keep sending positional data of bullets all the time.
The problem I foresee for homing missiles is that the server, who has the real state of all the objects at the time the homing missile was fired, will probably calculate the trajectory different from my predicting network clients. This could result in the missiles taking a different path on the client missing the object but on the server who is authoritative it actually hit. For the client it would appear the missile missed but a ship may explode anyway because of server registered the hit.
My plan is to give missiles, or at least homing missiles, their own NetworkViewID in Unity and send positional data from the server to ensure they take the same path. The downside is increased network traffic but I suspect missiles will have a low rate of fire and won't be coexisting for a very long time so it should be OK.
The past week I've slept between 3-5 hours per night and I think my son will be waking up in about 5 hours from (it's 1:41 AM now) so I best head off to bed.
I solved the issue. What I was looking for was the dot product comparing the velocity vector and the forward direction of my projectile.... Funny what guesswork can do =)