0
\$\begingroup\$

I'm trying to keep a 3d plane facing the camera at all angles but while i have some success with this:

Vector3 gunToCam = cam.cameraPosition - getWorld.Translation;
Vector3 beamRight = Vector3.Cross(torpDirection, gunToCam);
beamRight.Normalize();
Vector3 beamUp = Vector3.Cross(beamRight, torpDirection);
shipeffect.beamWorld = Matrix.Identity;
shipeffect.beamWorld.Forward = (torpDirection) * 1f;
shipeffect.beamWorld.Right = beamRight;
shipeffect.beamWorld.Up = beamUp;
shipeffect.beamWorld.Translation = shipeffect.beamPosition;

*Note: Logic not wrote by me i just found this rather useful

It seems to only face the camera at certain angles. For example if i place the camera behind the plane you can see it that only Roll's around the axis like this:

http://i.imgur.com/FOKLx.png (imagine if you are looking from behind where you have fired from.

Any idea what to what the problem is (angles are not my specialty)

shipeffect is an object that holds this class variables:
public Texture2D altBeam;
public Model beam;
public Matrix beamWorld;
public Matrix[] gunTransforms;
public Vector3 beamPosition;
\$\endgroup\$
  • 1
    \$\begingroup\$ I'm not very familiar with XNA anymore, but isn't there a Matrix.LookAt() function available? \$\endgroup\$ – Benjamin Danger Johnson Nov 8 '12 at 19:33
  • \$\begingroup\$ i tried Matrix.CreateLookAt but it resulted in the model displaying flat with no moment :( \$\endgroup\$ – Sparky41 Nov 9 '12 at 9:15
  • \$\begingroup\$ Interesting, well there are many ways to do this, and I don't feel like re-posting the answer (many people have the same problem) so here is a like to a similar post: gamedev.stackexchange.com/questions/15070/… \$\endgroup\$ – Benjamin Danger Johnson Nov 9 '12 at 17:45

Browse other questions tagged or ask your own question.