Another day, another dollar…

Status update:

Implemented the dual weapon system with some minor AI.  Enemies will only carry 1 weapon (Except maybe later grenades + weapon), and have unlimited ammo.  Players will now use whichever weapon has range, and then if the enemy comes closer switch to the shorter range weapon.  If the player has grenades and the enemy steps within range, the player will automatically arm grenades.

Heavy weapons and grenades have limited ammo: if the player runs out they will swap to another weapon.  If that other weapon was also a grenade/heavy, they will swap to a default pistol.  (Which was a pain, creating stats for a weapon that the player doesn’t “have”, so they can’t sell it for a weird, endless cash bug…)

Working with my talented artist, all weapons now have a reload animation, and those were edited and hooked up.  Reloading takes as long as the animation, plus the cool down of the weapon.  They look brilliant, by the way. :)

Besides having retarded AI, combat is pretty much done, in its basic form.  Time to move to formations, research, base management, story telling elements, leveling, interface, polishing and balancing…..


The Life of a Programmer/Designer

Alright.  So I got a bunch done today.

I added Bazooka shooting animations, added enemy machine gun animations, updated this website, created a combat scene, cut apart the explosion animations, created a new animation library for explosions, created a new sprite library for explosions, rockets, grenades, then I programmed the grenade object, the explosion object, the code to throw a grenade…

It’s been a long day.

But what got me caught up for an hour or two was getting the fake 3D, 2D grenade parabola correct.

It started out simple.  2 second throw, so take the start, take the end, divide by two, use that speed as the translation.  Great if you want to throw the grenade at the enemy like a fast ball.

Now, add a gravity like parabola?  On TOP of that linear motion, because in 2.5D that 2 dimensional move is just supposed to be the X…?

Well, I added a sine curve on top of the position each frame, but then that made the grenade just fly off into space.  Ah, adding every frame is taking the integral of the sine curve, which of course keeps growing.  So we need to add the difference.  But oh, hey, just in case it wasn’t confusing enough, the standard sin function is in radians, so make sure you remember your degrees to radians conversions.  And then remember you want the sine to divide by two because of the 2 second flight time.  And don’t forget that you want this to be frame dependent speed, so make sure to play with Time.deltaTime…  Anyways, at one point the line of code was like this:

transform.position.y += (Time.deltaTime * 10 * Mathf.Sin((Time.time – throwStartTime)/2)*Mathf.PI) – (Time.deltaTime * 10 * Mathf.Sin((Time.time – throwStartTime + Time.deltaTime)/2)*Mathf.PI);

See what I did there?  I hope not.  If so, please go make your own game.  Or work for me cheap.

Anyways, finally got it working after beating my (admittedly non-engineery) head against a wall for a while.  Here’s final code:

var arc : float;

//Flat travel variables

transform.position.x += Time.deltaTime * xspeed;

transform.position.y += Time.deltaTime * yspeed;

//Parabolic arc for Y

arc = 5*Mathf.Sin((Time.time – throwStartTime)/2*Mathf.PI) – prevYHeight;

transform.position.y += arc;

prevYHeight = 5*Mathf.Sin((Time.time – throwStartTime)/2*Mathf.PI);

Admittedly, after two seconds the grenades curve up amusingly, as per the sine curved, but I’ll handle that in a bit…