   Third Person Camera problems
  I'm having difficulty creating a third person camera. My first person camera is fine, but for third person, I want to move the camera back from the body, and have it a little bit in the air, looking down at my sprite. But I seem to be having difficulty in figuring out the order in which I'm supposed to do things.Currently, I take my sprite position, and create a view vector in the direction the sprite is facing. Then I move the camera back by scaling my view vector, and then I rotate it around the X axis to try and get the camera into the air and looking down at the sprite. I then get the camera position by adding the sprite position to the view vector. But of course, the camera is just at ground level, pointing down. It's not actually in the air pointing at the tank. I think I'm supposed to translate the view vector to the sprite position first, then rotate, then translate back. But I'm getting confused about what to translate and when.Any ideas? - Goishin   
  because you mentioned view matrix i presume you mean 3d, but you mentioned sprites, which tend to be 2d, i hope there for that this 3d information is relevant.Personally i would set up some collision/physX engine. I would then get the matrix of the objects from the PhysX engine and transform the graphics by the PhysX matrix.Then using this matrix i would invert it and then view transform by the inverted matrix. This would stick the camera on the position of you character and your cameras rotation is well, which would probably be the second thing you'd be asking.My website will have some of this code available over the summer so this question won't be asked again, i'll just point everyone in the direction of that. Till then look up matrix invert in MSDNshould look something like this:edit: the code is:D3DXMatrixInverse(&matView,NULL,&input);the middle value is put to null, you don't really need to know why.The view matirx converts all meshes to it. directx transform by world -> then view -> the projection (simple version). The view needs to be set before rendering all the meshes.In render loop do it in the following order:controlsmatrix of every mesh (including controller/charater matrix) changed/updated if needed/set-upview matrix set up by inverting the character/controller matrixworld transform and render objectstempView = Rotate(0,0,0)*Translate(0,50,-500)*matModel;D3DXMatrixInverse(&matView,NULL,&tempView);//matmodel = charater matrix.// Rotate and translate are my home made functions. Just use directx commands in there place.Hope that clears things upPureBlackSin;  Hey, thanks for the reply PureBlackSin. I appreciate you taking the time to give a shot at explaining things to me.But the explanation doesn't really make a whole lot of sense to me. I don't really see the point in adding in a collision or physics engine just to get a third person camera. That seems like a whole lot of extra work. Isn't it just a matter of moving everything back a bit and up a bit, and then pointing down at the target?And the rest of the explanation I'm having a hard time following. It may be that I didn't explain myself very well when I asked the question, or I may just not understand the subject material enough to understand the solution you're offering. Not really sure.Anyway, let me try asking the question in a different way.I have a working first person camera. What I'd like to do is switch to third person with the camera behind a little bit and angled so it's looking down at the target. I can get the camera to follow behind a bit, but I want it angled so that it's looking down at the target. And that's the part I'm having trouble with. I can't figure out the order in which to do things to angle the camera the right way.If someone could tell me the order in which to do things, that'd really help me out. Do I translate to the origin, then rotate, then translate back? What should I be rotating? The camera? Or the view vector? Or should I be translating to the center of the object, then rotate, then translate back?Thanks, - Goishin   ;  Hi, back again. basically if you don't want to include the physcis engine do the following,Translate/rotate scale charater matrix, note do not world  transform and draw the object first.Then use the inverse matrix like shown above, this sets how far back and the angle from the local position of the matrix.Now to apply matrices.IMPORTANT: Apply veiw matrices first, if not you get a nasty lag in your camera.then apply charater matrices to model.When i say apply i mean transform, so transform veiw matrix via the view transform (this skips the values such as eye, position and look at that you may have previously used and makes them redundant.). And also apply mean world transform and draw the models, e.g. charater that is being followed.So to conclude: (for the view matrix)take an identity matrix.rotate by wanted amount (= angle that the camera will be when looking down e.g. +-90 is looking down or up at the charater)Translate (the distance from the charater locally) e.g. if the front of the object is pointing in the +z directtion then you'd transform in the -z direction. to get directly behind your object.Transforimg by the model/character's model at the end makes all these transforms go from the worlds matix to the models matrix.Sometimes a bit of experimentation is need but that is the rough order.Obviously you could use quaterions, but i feel this is more straight forwards and not to computer intensive, as each time you times a matix you only do 64 addition sums.I hope this removes some of the confusion.PureBlackSin[Edited by - PureBlackSin on June 25, 2009 8:44:44 AM]