Game Development Community

dev|Pro Game Development Curriculum

More Realistic First Person

by Jacob Dankovchik · 08/11/2005 (3:29 am) · 73 comments

ANOTHER MJAOR UPDATE!!
This is yet another update and even MORE unsettling but realistic then other major update! This one will cause your camera to rotate with your head! In other words, walking is hard as hell, jumping throws your view everywhere, looking down is a pain in the butt and even walking can be a challenge, unless your model is configured properly in animations!!

Proceede and your own risk with this one!

In player.cc around line 3050, the functions
Player::getEyeTransform(MatrixF* mat)
and
Player::getRenderEyeTransform(MatrixF* mat)

Find the line that says
mat->mul(getRenderTransform(), pmat);

And change it to
mat->mul(getRenderTransform(), mShapeInstance->mNodeTransforms[mDataBlock->eyeNode]);


END OF UPDATE


MAJOR UPDATE!!
I completely forgot to add this before, and I feel rather ashamed. This was intended to be a very large part of this resource. The current code sets your camera and arm animations properly, but not your muzzle point for the basic animations.

WARING!
You may not want to do the following. When you run and shoot, your gun will point somewhere totally different unless you set correctMuzzleVector to true in the gun image settings.

in Player.cc around line 2050 in setActionThread, find "mActionAnimation.firstPerson" and "mActionAnimation.animateOnServer" and set them both to true

End of Update.



After a bit of playing the starter.fps demo, I began to get tired of the armless weapon floating in air and the lack of your own body showing, so I changed a simple variable that set it to draw your body. However this blocks out animation from your arms while in first person, so as you run they are totally rigid, along with your camera. I decided to take it even further and fix this too.

This is overall very basic and can be done in about a minute.

The engine changes all take place in player.cc, all around the same spot too.

The first is somewhere around line 3100, although yours may be quite different as my player.cc is modified a bit.

The first function to change is getMuzzleTransform, there is a small if statement we need to knock out.

if (mActionAnimation.action < PlayerData::NumTableActionAnims) 
   {
      MatrixF xmat;
      xmat.set(EulerF(mHead.x, 0, 0));
      mat->mul(getTransform(),xmat);
      F32 *sp = nmat,*dp = *mat;
      dp[3] = sp[3]; dp[7] = sp[7]; dp[11] = sp[11];
   }
   else
    *mat = nmat;

Simply take out the if and its block of code and the else so all you have left there is
*mat = nmat;

Scroll down a bit and you'll see the exact same thing in getRenderMuzzleTransform, and do it there. Then further down you see getMuzzlePointAI. I'm not sure when or where this function is done, but I changed it too just to be sure because these changes will make your weapon aim considerably differently.

Normally that would make it so only on certain animations would your muzzle point change with the animation but those changes there make it so it will always move with your animation.

This next part sets it to play all the movements while in first person. Normally your arms would be totally rigid, you could only see your legs move as you walk, but in third person you see your arms shifting all over the place. This makes it so you now see them go all over while in first person.

Around line 2300 in the function Player::updateAnimation, change
if (getControllingClient()) 
      {
         updateAnimationTree(isFirstPerson());
         mShapeInstance->animate();
      }
      else 
      {
         updateAnimationTree(false);
      }
by simply removing the if and its block so you only have
updateAnimationTree(false);
left over. Your whole body now moves in first person.

Thats it for engine. Next step is 2 minor script changes.

Open player.cs and find in the PlayerBody datablock
renderFirstPerson = true;
And set it to true. Then open crossbow.cs and find
eyeOffset = "0.1 0.4 -0.6";
and get rid of that. Save it all and compile and you should be good to go!

You may notice there are some minor flaws here and there with the Orc model, such as your camera peeking through it. Also you'll notice that as you stand in one spot, your crossbow no longer shoots to the middle of your view anymore, its a bit off to the side. Things like this would have to be fixed in your player's animation settings because thats where its all dependant on now.

Anyhow, have fun! I personally love this change and I think it adds a much more natural feel.
Page «Previous 1 2 3 4 Last »
#1
08/01/2005 (11:02 am)
Very cool, this should help with first person melee animations :)
#2
08/11/2005 (5:15 am)
Yes this is very cool.

I have a question about this comment.

Quote:Also you'll notice that as you stand in one spot, your crossbow no longer shoots to the middle of your view anymore, its a bit off to the side. Things like this would have to be fixed in your player's animation settings because thats where its all dependant on now.

What is it dependant on? Specific node[s] position?
#3
08/11/2005 (5:34 am)
Ya, as the node that the crossbow is mounted to shifts, the entire crossbow moves with it. Before it was fixed to point at the middle of your screen.
#5
08/11/2005 (6:25 am)
It would be a matter if keeping your eye node and mountpoint node alligned as much as possible.
#6
08/11/2005 (8:48 am)
ya, exactly. Although I really like that myself. It causes difficulty and inconvienience, but in my opinon, that makes it more fun. And things like running whill shooting will actually throw you off. And with your camera moving with your eye node and the rest of your body moving too, you could do somethin like animate your player to trip and fall and it all easily works.
#7
08/11/2005 (1:17 pm)
Just make sure you have correctMuzzleVector set to false in your image datablock, and it should shoot where your recticle is pointing(unless this code breaks that feature).
#8
08/12/2005 (7:14 pm)
This is the best thing to happen to me since sliced bread! I was trying to do a head-bob feature, but this is even better! Thanks a lot.
#9
08/12/2005 (8:34 pm)
Hehe, glad you like it :) Seems to have worked out well for my first resource attempt.

oh, and
Quote:Just make sure you have correctMuzzleVector set to false in your image datablock, and it should shoot where your recticle is pointing(unless this code breaks that feature).

Yes, it does break that.
#10
08/13/2005 (8:18 am)
Thank you Jacob, this is great!
#11
08/13/2005 (7:59 pm)
This might sound dumb but when i do this how do i complety recomplie the engine...And if i do recompile the game again what and where will it put the files that it creats?? I know that theses questiosn sound dumb but i am a numb with this engine..But so far it really seams to be quite user friendly...
Matt
#12
08/14/2005 (8:07 am)
Well, that could be different depending on how you got things setup. Read the documentation about compiling or ask in the forums in Getting Started.
#13
08/22/2005 (7:34 am)
Jacob:

Thank you thank you thank you! This eliminates about three different things on my list of player-animation-needs. Awesome job!

Glez
#14
08/22/2005 (5:17 pm)
Hmm, I was having problems with the aim being off and all, but the correctMuzzleVector fixed it for me. When I set correctMuzzleVector to true, the crossbow aims just like it used to. Yay!
#15
08/25/2005 (8:12 pm)
Wonderful resource, dropped it into 1.3 in about a minute.
Woot! I can see my feet!
This mod made me notice things that were allready wrong with my game, like the character's idle "bob" was a little excessive, and some other minor things.
This makes melee feel really up close and personal. :)

Ari
#16
09/02/2005 (11:45 pm)
Does this resource allow the player to see hands holding the weapon like it is with most FPS?
#17
09/03/2005 (5:16 am)
Yes, you'll see your entire player model basically. What this does is makes the player model draw while in first person and fully animate.
#18
09/04/2005 (3:22 am)
Wow. That's cool then. Always wondered how to change the floating weapon in Torque. Now to get weapon reloading done. Anyone know how to do that?
#19
10/04/2005 (6:49 am)
Great resource, dropped it in, recompiled and it worked without a problem. The only visual flaws I see are specific to the model.
#20
10/04/2005 (7:20 am)
What visual flaws are there?
Page «Previous 1 2 3 4 Last »