I lost my vector (Astrofighter.Net)

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.

Today’s progress

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.

Vector confusion

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.

Signing off

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.

Update:

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 =)

 

Posted in Astrofighter.Net, Imphenzia Games | Tagged , | Leave a comment

Astrofighter.Net Development Update

Last night and today I rewrote the weapon class for Astrofighter.Net so that it can support a wide range of custom properties for each weapon. I’ve added about 40 properties so there will be a great number of ways to upgrade weaponry using powerups.

Here is a short video demonstrating two of the properties named “ChargeUp” and “Multiload.” If “ChargeUp” is applied to a weapon you can hold the fire button down to increase the power/velocity/life of a shot. The “Multiload” upgrade allows you to hold the fire button to load X number of rounds before discharging the weapon.

Posted in Astrofighter.Net, Imphenzia Games | Tagged , , | Leave a comment

Astrofighter.Net – Now suddenly loving C#

Today I redesigned the code for weapon handling in Astrofighter.Net and the game now supports very dynamic creation of weapons and weapon upgrades. Each weapon is configurable with tons of settings such as various sound effects, autofire, charge up for increased power, rounds per minute, and so forth. In all there are about 40 customizable settings for a weapon and for potential powerups / upgrades.

While rewriting, and documenting, my code it strikes me how much I’m starting to like C# and the intellisense autocompletion of all variable names and functions. Today I learned about the ability to use the {get;  set;}  feature to treat a variable as a property – quite nifty. What this means is that you simply define a variable like this:

public float velocity { get; set; }

This enables you to from other scripts access the variables directly:

// this automatically uses set
remoteScript.velocity = 10;
// this automatically uses get
Debug.Log(remoteScript.velocity);

The only downside is that you can’t have these variables show up in the Unity inspector to assign them a default value which is a shame. There is a workaround for this in Unity but it requires a bit of code bloating so I simply don’t use inspector configured values in this case.

I’m very happy with today’s progress as it enables me an incredible level of control of my weapons and powerups. Should be able to create tons of cool upgrades that split bullets, enable homing missiles, alters velocity and force of projectiles, and so on.

Posted in Imphenzia Games | Tagged , , | Leave a comment

Astrofighter.Net

Astrofighter.Net is my new game development project for learning Unity and C#. During the past week on every spare moment I’ve been able to find I have been developing and creating assets for the game. When I’m not on the computer I am coming up with about a billion ideas for the game, or at least so it feels like.

If you want to read about Astrofighter.Net directly – skip this next section =)

The dangers of being in a situation such as mine is starting a tremendous amount of projects and never finishing them. With “a situation such as mine” I mainly refer to the wide spread of hobbies I have, all of which must fit in to an otherwise normal life. Non-computer based hobbies aside (motocross, photography, martial arts, spending time with wife, two children, and friends) I am, as many of you are aware, currently dedicating much of my time to:

  • Being the independent electronic artist Imphenzia with 85 tracks and 6 album releases to date – this includes maintaining my custom created artist site, maintaining presence at Spotify, Youtube, Facebook, Twitter, Soundcloud.com, Soundclick.com, and Ubetoo.com. The custom web site is created in PHP and I think it’s the 6th generation (each being a complete rewrite.)
  • Being the composer Imphenzia Soundtrack with over 250 songs/loops and 260 sound effects available for licensing – this also includes maintaining the custom created site.
  • Being the game developer and graphic artist Imphenzia Games with completed 3 game releases (Beat Ball, Beat Ball 2, and Netris.) Again – maintenance of the custom created web site for the official site and Beat Ball 2.

I’m proud of my achievement over the years, especially fitting all of it in next to my every day that normally takes up 8h + 2h commuting every weekday. I have one project, however, that has been my bad conscious for a long time. It’s been nearly 10 years since I started “Computer Touring Car Championship” (CTCC) which was later renamed to “Performa Cars.” This game is still unreleased but as I recently announced in a blog post I will release the game but without network multiplayer (only split screen), and it will be freeware since it’s using such dated technology.

I have to accept defeat when it comes to implementing multiplayer in Performa Cars simply because I didn’t consider the nature of network gaming when I started making the game. It would take a complete rewrite of the game (more or less) to make networking work and it would not be time well spent since it’s using unaccelerated 2D graphics that probably utilizes less than a single percent of today’s graphics cards. Seriously.

There is new hope, however. I’ve used BlitzPlus, Blitz3D and BlitzMax to develop Beat Ball 2 and Performa Cars and I’ve really enjoyed the Blitz-range of products over the course of 10 years. Lately I discovered Unity3D and I first dismissed it a year ago. Who want’s to make a game in an “editor” I thought?

How to waste time

No, I thought. I want full control of my game development. I need to see every line of code and be sure I structure the games exactly how I want. This is how you waste a lot of time by the way =)

In Unity I trust

When I gave Unity a second chance, I looked at a whole bunch of video tutorials on YouTube. The tutorials explained Unity in a step by step manner, going through the editor, all the windows, hierarchy, types of game objects and so forth. Unfortunately I can’t remember which series of tutorials I watched – but Google the topic and I’m sure you’ll find many great tutorials. Giving the step-by-step demonstration of Unity a chance helped me tremendously and I fairly quickly started to make some simple scenes with a bouncing ball, colliding objects, particle systems, etc.

My ultimate goal is to re-create “Performa Cars” as what I refer to as a “2D-but-3D” game with the multiplayer functionality it so much deserves. Using Unity instead, I’ll be able to cut down development time and also make great use of the power of modern computers and graphics cards.

My “2D-but-3D” approach, as seen in Beat Ball 2 and in the coming Astrofighter.Net game, is making the game look like an old-school 2D game but using the visual and physics power of 3D engines. I think many developers are too tempted to tilt the camera down into the 3D scene since “it’s possible.” And I agree 3D games are awesome, but I am fighting the temptation to tilt the camera as I want to make 2D games and I know there are a lot of fans of 2D games out there so this one is for you =)

Rather than jumping straight into making the new top down racer in Unity I wanted to make sure I know how to develop a multiplayer game. This is why I am first attempting to make a simple multiplayer space shooter game.

Astrofighter.Net

As I mentioned early on in this post, I’ve dedicated a lot of my time the past two weeks when I started a real stab at creating a game in Unity. I am amazed at how fast I am able to make progress in Unity being such a novice at it. In just a matter of two weeks, Unity has enabled me to create the basic foundation of space combat game that already supports server side authoritative network multiplayer with client side prediction.

I captured the footage above today as I tested the current build of the game with two of my mates. It runs very well already although latency is very low at 30ms so I’ll do more thorough testing using a 3G modem with 150+ ms latency. The YouTube version of the video is choppy since YouTube reduces the frame rate from 60 FPS to 30 FPS. You can download the 60 FPS H.264 version of the video to see exactly how smooth the game flows.

So far I’ve implemented the basic networking code, the spawning of player ships with the choice of two weapons. A Blaster and an 80mm Gatling Gun Cannon =) The blaster is single fire and the Gating Gun fires 800 rounds per minute. There will be loads of ship types and weapons with upgrades – I have an excel sheet with loads of goodies and ideas.

The game uses true physics with rigid bodies and real life forces. I’m really happy with how easy Unity is allowing me to just assign my ship, for example, a weight and what force it should apply during movement and the physics is just “taken care of.” It also looks very promising how I can use the physics aspects even during multiplayer.

To prevent cheating, and to ensure collisions don’t behave differently, the server takes care of all the physics and collisions in an authoritative way. The clients also animate the objects but if a cheating player hacks the game to move twice as fast on his own computer the server will warp the player back to where he belongs. Feminists can attack me now since I referred to the cheater as “he” but surely women don’t cheat, right? =)

Is it a felony to have this much fun?

I’m having so much fun with this project that I even feel stressed when taking a break. This lengthy blog post is also hogging time from Astrofighter.Net but I want to make sure to post about my progress.

Today I also registered Astrofighter.Net – and I know I know – there was a game from 1980 named “Astro Fighter” but I don’t have a space and I added “.Net” to emphasize it’s a networking multiplayer game.

Posted in Imphenzia Games | Tagged , , , | Leave a comment

Redeemed myself today

I’m happy to day that today I redeemed myself from yesterdays failures.

Getting the missing parts

After today’s daily pickup [of my child at daycare] I set off to buy the toilet seat, the front brake disc, and the hand guard mounts that I failed to get yesterday. My son only threw up once on the journey as well, that’s not bad. Also, he refused to exit the huge plastic car attached to the shopping cart at Bauhaus so we were stuck in the parking lot for a god 10 minutes convincing him that it’s much more fun traveling backwards in our real car so he can throw up properly again.

Raycast my bullets please

I also managed to implement a great Raycasting bullet script in Unity3d. My previous bullets, or projectiles, were using rigidbody physics and a collider but even with continuous collisions enabled my fast moving bullets went through obstacles. This is not uncommon in Unity from what I understand which is why I had to switch to Raycasting instead.

Basically, raycasting is when you look ahead a certain distance to see if the bullet will hit anything whereas the rigidbody method just teleports the projectile forward and if the step is large enough to step from one side to the other in once fixed timestep, the bullet will just bypass the object. So – check out the link to the bullet script if you have no knowledge of Raycasting in Unity – it helped me out a great deal.

I did do one modification, however. When a rigidbody is hit, I apply AddForceAtPosition (instead of AddForce) in order to introduce torque on the object hit making them spin nicely:

hit.collider.rigidbody.AddForceAtPosition( transform.forward *
    impactForce,transform.position, ForceMode.Impulse );

Shader to make a shielf / forcefield

I also managed to give my spaceship a nice force field shield using a custom shield shader in Unity. Since my little game is top down view I didn’t quite get the nice effect as seen on that page – so for the time being I apply a plasma texture that is animated across my ship and it looks quite nice.

Tomorrow is another day

Well sort of anyway. It’s 01:59 AM and I have just queued up what to think about when heading off to bed. I’ll use some of my brain’s processing power to figure out how to best structure the assets for my little space fighter game. I’m hoping to get a prototype of the game up and running in a couple of weeks. It’ll just have one space craft and one weapon – but most importantly – multiplayer must work!

 

Posted in Imphenzia Games, Personal | Leave a comment

I nearly did so many things today

I went to town today because I had to do three things. 1) Eat lunch with a mate of mine, 2) go to 24MX and buy a new front brake disc for my motocross bike and get a missing mount for the hand guards for my enduro bike, and 3) get a new toilet seat from Bauhaus. I had enough time for 1) and then I had to go back to pick up my son from daycare…

See it’s not that sharp

I’m switching to C Sharp (C#) from Javascript (JS) in Unity3D and it’s slowing me down at the moment. I’m switching because I kept being told that C# is so much better – but so far my experience is that you just have to write more code and find workarounds for stuff =) Still, I gather I’ll find use of C# knowledge so I’ll persevere. It’ll also help me from snarfing code because most code is Javascript and if I manually convert it to C# I can understand it better… and improve it?

The bottom line is that I haven’t managed to get very far today on my Space fighter project today. I’ve got my ship flying around with mouse and keyboard control, I can fire an animated blaster canon, and I found out the Dynamic collision detection in Unity can’t really be trusted. Oddly enough the bullets collides with obstacles all the time, perfectly, in the editor – but not in the compiled version? I decided not to troubleshoot it any further because I use fast moving bullets and from what I gather I should be using raycasting instead so that’s something I’ll look deeper into tomorrow.

I nearly bought Harmor

Harmor VST - doesn't like 64 bit hosts

No, not armor. Harmor is an awesome sounding additive / subtractive synthersizer VST instrument. I mate of mine told me about it today and I downloaded the demo just to find out it’s a 32bit VST instrument and I run Cubase 5.5.3 x64 (64 bit). Harmon crashes Cubase for me after only a few minutes of use, gah.

Well, before buying Harmon – I thought I’d contact Image-Line (developer of Harmon) and ask them about their plugin crashing in Cubase. Image-Line support have no contact details on their web page and they direct all technical inquiries to their technical support forum…. Well, their technical support forum only appears to be supporting “FL Studio” because after registering in their forum I found out I have no authorization to post any questions in their support forum (which is also titled “FL Technical Support”.)

I then found out that VST Bridge (the component that keeps crashing in Cubase when i use 32 bit plugins) is not to be trusted if I go by what forum users at Steinberg say. Instead there is a suggestion to either downgrade to 32bit Cubase (which I don’t want to do because I have 24 GB Ram for my orchestral libraries and 32 bit Cubase would allow me to use about 3 GB of that memory at best), or use JBridge (or Bitbridge that I never found anywhere.)

jBridge

I downloaded the demo version of JBridge and it took me a few launches of the installer to figure out what to do, but I found a simple step by step instruction and using that the installation worked great.

Harmor seems more stable using JBridge, but it’s not hassle free their either. Quite a few times during half an hour of use Cubase froze, the Harmor GUI turned white with nothing in it, but I found some features I could enable in JBridge that seems to have combated most of the issues. Just as I write this I get “IL Harmor.dll – Forcing auxhost termination due to an error. Dispatcher: 19; Audiomaster: 15″ – and IL Harmor turned bright white again. Now I got “Dispatcher opcode 19 failed (IL Harmor (demo)/1229483375).” -but wait – I saw something in the help for that…  I have to enabled “I am getting a dispatcher opcode 19 error message” – great, I love it when I know what’s happening.

Well, I’m not convinced JBrige will solve any stability issues – I just seem to get other types of stability issues.

Summary

Today

  • I nearly bought the front brake disk and hand guard mount (but time ran out)
  • I nearly bought the toilet seat (but time ran out)
  • I nearly made some progress in Unity (but C# & buggy collision detection stopped  me)
  • I nearly bought the Harmor  VST (but it’s 32bit and buggy)
  • I nearly contacted Image-Line support (but you can’t)
  • I nearly bought JBridge (but it just changes the bugs around)
  • I nearly went to bed in time, but now it’s 3:12AM

Posted in Imphenzia Games, Imphenzia Music, Personal | Leave a comment

All the children get their own (voodoo) doll

I was told off today and rightly so! My son has been in daycare for two weeks now and “I STILL hadn’t sewn his doll” one of the staff reminded me in a friendly but firm manner.

All the kids have dolls that their parents make for them in case they need comforting. They can also be used when resolving conflicts between children where they act / replay an event using their little dolls.

Me? I’m convinced it’s a voodoo doll!! Since I’m the one who sewed it I’m sure my son will be able to inflict great pain even when he’s at daycare.

Anyway, I had to give the doll full priority tonight and sewing isn’t one of my strong skills. I just finished it now and I hope he forgives as he will probably have the plainest looking doll of all children. I overheard the mothers discussing the dolls last week. It was all about fashion, choice of fabric, what accessories to make them, and so forth. To make up for the lack of detail I gave the doll a superhero cape (and some awesome superhero powers.)

Superhero doll

 

 

Posted in Personal | 1 Comment

Full cone NAT UDP holepunching or just a hole in the head?

So far I’ve wasted about 8 hours of my time trying to get the masterserver communication to work in Unity3D. I’m currently troubleshooting Network Address Translation (NAT) issues that prevent my test game from acting as a server.

So far, I’ve tried to get it to work through my existing firewall/router which is a virtual machine running pfSense. Despite configuring uPnP and outbound NAT according to this pfSense forum post to emulate what’s referred to as Full Cone NAT it’s been a no-go. Unity’s networking test function still claims it is Port Restricted NAT which then means I can’t really host any games.

Ok – what about my Cisco LinkSys WRT320N router – I’ve got that one set up as well with it’s own public IP address. I changed my default gateway to this device instead, and behold, it didn’t work. That device also has a poor implementation of uPnP and NAT traversal so that does not work either. I found this list of devices that describes which NAT-type each device supports and whether or not it supports UDP-Hole Punching. It turns out that the vast majority of routers don’t support this very well which explains why the world of multiplayer gaming seems to spend more time speculating and trying to get a game to work than actually playing it.

Hole in the head – and in the firewall

To be fair, uPnP is an idiotic invention anyway. The idea is that any application can tell the firewall to open itself up. But wait a minute… what if I have a trojan (like Skype =) can that just politely say “Open Sesame” and let all the baddies in? Yep. That’s right.
So then, we have uPnP (which stands for Universal Plug and Play) a desperate attempt to solve communication in the world of NAT… and we have most devices implementing uPnP poorly to make it even worse.

Hole in the head.

Is there any light at the end of the funnel?

NAT is used for a number of reasons, one being that there are not enough IPv4 addresses available (only 4.3 billion) to allow all the computers in the world to have a unique address. This means that internal networks usually have addresses in the private ranges such as 10.0.0.0/16, 172.16.0.0/12, and 192.168.0.0/16 which are then translated between the private network and the Internet. There are also security benefits with NAT, for example, by default (more or less) an internal host must initiate traffic to an external host before the external host can communicate back to the client host.

My hope is that IPv6 will solve the NAT-mess in the future. IPv6 has such a large address space (340 undecillion) that in theory NAT wouldn’t be needed. How many IPv6 addresses are there I hear you wonder? Well, someone with enough time on their hands calculated that every square millimeter on earth’s surface could each be allocated 170,000,000,000,000,000  IPv6 addresses.

But wait… IPv6 is currently being implemented and we can’t just switch from IPv4 to IPv6 as nothing would work. How to we solve the transition then? Let’s go with our buddy NAT again… now with the selection of more implementations – how about 4in6, 6in4, 6over4, DS-Lite, 6rd, 6to4, ISATAP, IVI, NAT64 / DNS64, Teredo, TSP, TRT, SIIT, Drafts, 4rd, AYIYA, dIVI, NAT-PT, NAPT-PT…. Have fun troubleshooting why network multiplayer gaming isn’t working during this transition period =)

Do I sound negative? I wish we could just format the world and start over with stuff that just works instead.

Posted in Imphenzia Games | Tagged , , | Leave a comment

Networking with Unity3D

For years and years I’ve been wanting to create a network multiplayer game. Ok, I already created one about 10 years ago called Netris but that is a type of game that does not rely on any sort of speed or major synchronization of game data.

I tried to implement network multiplayer capability to Performa Cars (previously named “Computer Touring Car Championship”) – but I had to throw in the towel in the end. Too many design issues with the game itself (how the physics was implemented) and lack of proper networking libraries for Blitz3D proved to be too big of an obstacle.

New hope

Today I bought an asset package called “Ultimate Networking Project” for Unity 3D. It’s a combination of a tutorial and a bundle of useful scripts and functions to simplify multiplayer networking in Unity. I’ve read through the 25 page tutorial and looked at the included examples and I’m very hopeful to be able to create a multiplayer game in Unity.

What appears to be promising in Unity is built in functions for interpolation/extrapolation of object positioning along with client-side prediction and server authority. If these terms are alien to you, let me assure you that they were to me as well when I started to make Performa Cars. It’s a world of hurt if you have to learn and develop all these functions by yourself – but as I mentioned, Unity appears to have this under control.

My first project is to create a simple top-down space shooter (using the low polygon 3D spaceship I recently designed.) The purpose of this project is to learn enough about Unity and networking to have another go at the top-down racing game I’ve always dreamed of creating.

Posted in Imphenzia Games | Tagged , , | Leave a comment

How I arranged the trance track Spirit Within You

Following some very positive feedback on the tutorial video on how I create trance music I also decided to dedicate today to make another tutorial of how I arranged the entire track Spirit Within You.

This video takes a detailed look at all the sections that form the track – such as the intro, the build up, the breakdown, the culmination, and the outro. It also explains how various instruments are introduced and modified during various stages of the track.

I am, by no means, saying that this is how you must make trance music – it’s just at peek into how I arrange most of my tracks. When I started out making music in the 90s I found no tutorials like this and I’m hoping that this video can help some of you that are interested in making music.

Right then, here is the tutorial of how to arrange a trance song / track:

As usual, I use Cubase 5 and my trusted VST instruments Nexus2, VanGuard, and Sylenth1 – but this arrangement technique can be applied regardless of what software you use.

If this tutorial helps you out – I’d be happy to hear about it in the comments field =)

Good luck and happy music making!

Posted in Imphenzia Music, Imphenzia Tutorials | Tagged , , , , , | 1 Comment