Game Development Community

3rd person camera implementation borks animations

by Ben Mathis · in Torque Game Engine · 07/25/2007 (7:16 am) · 13 replies

Tried to create an external 3rd person sideways camera. Had lots of problems with using the camera object (as well as the AdvancedCamera resource, it does not work) as it seems that the camera object is only used when it is set as the control object (useful??). As a solution to that I tried to change the getRenderEyeTransform function that is used to render the scene by creating another function called getRenderCameraTransform and use that one instead of getRenderEyeTransform in ShapeBase::getCameraTransform and modify the rotation and location of the render caption. Setting the character up as the control object seems to mess up the animation sequence of our character. When the Camera is set as a control object instead of the character, our character's animation runs correctly, when our character (with the changed render function) is the control object, the animation gets scewed. Here's what I did in getRenderCameraTransform (red text is code I changed):

void Player::getRenderCameraTransform( MatrixF* mat )
{
   MatrixF pmat,xmat,zmat;
   xmat.set(EulerF(mHead.x, 0.0f, 0.0f));
   zmat.set(EulerF(0.0f, 0.0f, mHead.z-1.5));
   pmat.mul(zmat,xmat);

   F32 *dp = pmat;
   F32* sp;
   if( mDataBlock->cameraNode != -1 )
   {
      sp = mShapeInstance->mNodeTransforms[mDataBlock->cameraNode];
   }
   else
   {
      Point3F center;
      mObjBox.getCenter(&center);
      MatrixF eyeMat(true);
      eyeMat.setPosition(center);

      sp = eyeMat;
   }

   const Point3F& scale = getScale();
   dp[3] = sp[3] * scale.x+7;
   dp[7] = sp[7] * scale.y+1;
   dp[11] = sp[11] * scale.z;
   mat->mul(getRenderTransform(), pmat);
}
Even only changing the y offset (to see the character from behind) shows that the animation is crooked, but only when the character is the control object.

Here is an image of the problem. See how the feet seem to detach? In Showtools, this place perfectly (ankles stay connected and she seems to just be breathing heavily)

www.poopinmymouth.com/net/escapade/bug_01.gif

#1
07/25/2007 (9:21 am)
Ben,

Well now I'm feeling like a hoser. I see you did try the Advanced camera and it didn't suit your needs.

I feel like I've trounced you badly now, especially for a guy with so many free tutorials on his site.

I'm going to get breakfast and my coffee (I'll blame it on that) and take another look at this whole question again.

Cool?

So, sorry to whack you like that and let me start over in a few minutes...


-Ed M
#2
07/25/2007 (12:22 pm)
Ben,

Hi. OK. I tried out your code and have a few questions, but first, let me lay out the steps I took.

1. I Added a new method to the player class named: getRenderCameraTransform().
- This compiled fine.

2. Based on what you said above, I tried to replace calls to getRenderEyeTransform() with getRenderCameraTransform() in ShapeBase::getCameraTransform().
- I didn't expect this to compile and it doesn't.
- My guess is I misread your instructions/notes above.

3. I swapped the bodies of Player::getRenderEyeTransform() and Player::getRenderCameraTransform().
- This compiled and ran.
- This showed rendering issues, but not the one you mentioned.
- This affects your render transform and will have side-effects you don't want.

4. I thought a bit, and asked myself the question: "What is Ben trying to do here?"
- It looks like you want a camera that tracks the player like 3rd POV, but has the ability to change its position to any set viewpoint. (See image below)
- You say you've tried Advanced Camera but it didn't do what you wanted?

gamers.hallofworlds.com/support/other/trackingCamera.jpg

5. I put together a sample mission using the advanced camera resource and tried to emulate what I'm seeing in your animated GIF.
- I uploaded this to one of my alternate web sites. You can download it here.

Meanwhile, could you please elaborate on what you're trying to accomplish? That will help tremendously.

-Ed M.
#3
07/25/2007 (2:19 pm)
Well the goal is to get a 3rd person camera, fixed in the position/angle you see in the gif, but we want to add a slight ease in and ease out whenever motion changes (start to stop, stop to start, etc).

I'm actually the artist, but since I'm more forum savvy, I'm posting for the programmer. He tried implementing Advanced Camera, but it was a bit too advanced for his level right now. He's coming from an AI background for robotics, and this is his first forray into 3d game programming.

If you can think of a good way to do this using advanced camera, we're definitely up for it, but we were hoping for a possibly simpler solution.
#4
07/25/2007 (7:01 pm)
Ben,

Looks like you got a couple of reposts there. That happens sometimes when you refresh. You can easily delete the extras.

I'm sorry I didn't reply, but I've been out since 1300 my time (nearly 1900 now).

I hear what you're saying and will think about it, but I've got some work to do now.

Please let me know what you thought of the download I set up ( you can get it here.)

Alternatively, here is a short video of the effect: video

Is that similar to the effect you want?

Run the demo and hit TAB to get into 3rd POV. The view will be off to the side.

If this is close, I'm sure that adding a little lag into the equation won't be a big deal.

I also have scripts for making it simple to adjust the camera position using yaw, pitch and distance settings.

-Ed M.
#5
07/25/2007 (7:19 pm)
@Edward F. Maurina III

You overly helpful guy you!!

:)

I was going to help on this one, but when I saw you jumping in I knew I should just sit back and watch the expert. :)
#6
07/25/2007 (7:26 pm)
Anton,

Thanks, but I'm sure Ben would love any help he can get. There's nothing like having several brains all trying to come up with a solution to an interesting problem.

...sssssssss

Sorry, had to let some air out of the old head there. :)

-Ed
#7
07/25/2007 (7:33 pm)
:( video won't play for me. What codec did you use?
#8
07/25/2007 (7:49 pm)
@mb,

Here is one encoded w/ divx 6.1 video

.... dropping off the grid now.

(=Ed
#9
07/26/2007 (2:39 am)
Sorry for the reposts. Also, we're both on GMT because we're in Iceland, so sometimes our responses might be a bit late. Thanks for the video/code Edward, I'll have Agust try it out tonight. I do have a few responses from him about the rest of the thread.

The only thing I changed in ShapeBase::getCameraTransform was at the very end of the function:
.
    .
    .
    else
    {
         //getRenderEyeTransform(mat);
        getRenderCameraTransform( mat );
    }
}

plus adding getRenderCameraTransform to the Player class, as well as to the ShapeBase class as a virtual function. I dont see why that shouldnt work on every version of the engine...

I have tried to implement the AdvancedCamera and succeeded at that but it messes up the double jump I have implemented plus it has an annoying view-skew effect whenever the character is moved back or forth. When I don't use the AdvancedCamera, the double jump works perfectly.

I also tried to make the camera the control object. I gave it a reference to the player object and called processTick on the player from the processTick in the camera object whenever that one was called. This did work but was super jerky and thus, unusable.

I'd love to hear how everyone here would create a 3rd person sideways view.
#10
07/26/2007 (9:11 am)
Ok, Agust has tried your implementation Edward, and here is his comment:

I tried implementing some of the script that Edward sent around, replacing my version of GameConnection::createPlayer (in server/script/game.cs) with the one provided by Edward as well as reinstalling the entire engine to make sure -any- change I might have done to the engine werent interfering. Unfortunately, this didn't have any effect, it's still ignoring everything and using the 1st person perspective (I also tried calling GameConnection::setFirstPerson( 0 ) to make sure it is being set, if that has anything to do with this, the only thing that did was to send the rendering caption to somewhere miles above the character) . Is there some script snippet I didnt catch for this to work Edward?
#11
07/26/2007 (12:43 pm)
@Ben,

1. Ah..., virtual method. Yes, that would work (compile).

2. Haven't had time to digest the rest of post that started with "Sorry for the reposts..."

3. Regarding the trial run with my scripts:

a. I changed the files:
server/scripts/commands.cs
server/scripts/game.cs

b. I added the file:
server/scripts/advCamera.cs

c. I suggest moving your model over into my example (if you don't have engine dependencies).
For debug and comparison purposes this is simpler than moving my script changes into your game.
Why? Because then, the only difference from stock TGE 1_52 would be:
- My addition of AdvancedCamera classes.
- My script mods (listed above)
- Your Model (instead of Orc model)
- Your datablocks (instead of Orc DBs)


I'm sorry, but I need to eat lunch and head to work for some meetings, so I'm going to be away for several hours.

(I know these discussions can be tedious, especially with time zone differences. )

-Ed M.
#12
11/07/2007 (9:00 am)
I know this thread is almost dead but would it be harsh to ask if I could peak at one of yalls source files where this is implemented. I have been trying for about two days off this resource to get it to work with my source code but I dont think I know enough to get it running.

if you could upload it to here or email it to me id be extremely appreciative.

Thanks
Brian k.
#13
11/07/2007 (11:49 am)
Lol never mind, implemented another resource that conflicted with advanced camera and caused my key rotations to be messed up.
Thanks