07 March 2013

Exercising those Animation muscles

Here's an update for that FPS program I've been working on. Which is really only to work out simple animations and find the best ways to control the camera. Turns out that if I attach the camera to a blank game object (one that is only a transform) I can set a perminant rotation/placement, and a temporary one as well. For instance: I lean the camera.main to the right slightly when aiming down the iron-sights, this is a one time call that does not update every frame, a perminant change. I added some walking head bob to the camera that rotates the camera left and right, this actually rotates the CameraMount that the camera is attached to, and is a temporary change. And I have code running every frame that Lerps the camera Mount rotation to a relitive 0 ( the mouse position). Camera bob is a simple on/off switch bit of code that rotates the camera in a downward direction either on the left side or right side. I added some forward drop of the camera each step as well, to hopefully give this all a more natural walking feel to it. I also added a touch of bobbing motion to the gun when you step, Which has to adjust down when you zoom. Added some gun kickback when you fire, as well as a slightly random camera-kick that when firing at a more rapid pace causes accuracy to go down. and again, No recorded animations, :)

press 'C' to toggle full auto.

02 March 2013

An exercise in FPSs

I started work on a little exercise to improve my animations and slim down my code a bit. After looking at the horrendous code I put into the last FPS, I wanted to build a better engine. It's a simple FPS, WASD controls, Spacebar jumps, shift runs, left-click shoots, right-click uses "iron-sights". I went with a more traditional culling feature to prevent the gun from clipping through close objects, but that was about that. The animations are not recorded, they are hard-coded, which takes up quite a bit less space and processing power. Projectiles are little balls with a tail attached to allow them to be easily seen when fired. Due to the fact that they fly at such high velocity, the engine has to render the bullet in steps, between frame one and two  the bullet may cover several yards, but will only be displayed at points one for frame one, and two for frame two. This caused the bullets to fly through the objects I was shooting them at, unless they were right at the frame area. I used an old code idea that casts a ray from the projectile, towards the direction it is flying, using the distance between frames as length (which is based off of velocity) and any object hit causes the projectile to turn on it's collider (i can't quite remember why I instantiate it without a collider, then later turn it on when it is supposed to hit an object, but i like the effect and it's not spending process power looking for collisions, just the raycast script i wrote), it also will be transported to hit.point, the point of raycast collision, and while maintaining it's velocity, and now having a collider, causes an impact on the target in proportion to the masses of both objects. Because the bullet's mass is so little and the dummy and target is slightly higher, they react naturally.

The other experiment I was working on a little was ragdoll effects, the dummy uses spring hinges on it's legs and feet, and the target "hangs" by a spring hinge, which you'll see in action if you shoot it or run into it.

Here's another divergence from traditional FPSs that I wanted to make note of: I tilt the camera when using Iron sights on the rifle. It feels strange at first, but later starts becoming natural and expected, I have even caught myself tilting my own head involuntarily to simulate the action in real life while playing. Most games pull the gun up the center of the screen to look down the rails, which you would have to, but when holding a rifle, you lean into it a bit, some head tilt is going to happen. Now, another thing that may be different, may not be so is that the projectile Actually comes out of the end of the barrel, that is to say that the bullet is instantiated at the end of the barrel, as apposed to the center of the screen, so when holding the gun at the hip, the bullet will not fire directly at the center of the screen, it will be slightly off to the right.

https://www.dropbox.com/s/40jfzlykcqn4wd7/FPS%202.zip?m