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
That's awesome! It feels so much smoother than that first attempt, and I'm really digging the slight tilt at the iron sights. It all felt really natural, except for the jumping, which was still a bit floaty. The only other thing I noticed was that a couple of times, my cursor wandered out of my first monitor and onto my second, and when I clicked, it minimized the screen. There's got to be some simple thing where you can lock a cursor to a window.
ReplyDeleteBut yeah, all in all, it seems like a huge improvement over the older version. You planning on letting this one take center stage over your other projects? You could use the menu system you built for the runner and apply that to the inventory manager thing you had going on. I'm looking forward to seeing more!
Yeah. There are a few things I could work on. The jumping part was generic code I copied from another project. Some of the animations snap to their final positions a little too much. But overall the amount of code I used is the major upgrade in the fact that i've been able to minimize it to the maximum extent possible and it still work the way I want it to.
ReplyDeleteOh yeah. No this will not take precedence over the autoscroller. It was originally an exercise in animation with physics and hinged joints. Instead of recorded animations I would rather code all the movement.
ReplyDelete