c# - Weapon on first person -


My team and I are successfully trying to display our weapon on the screen for a week: in fact we Need help with it What we want to achieve, like in every FPS, display the weapon with a slight horizontal offset on the screen, as if the player was holding it.

We have tried to use the matrix already, but without success: Weapons are not even visible, it is behind us, and even if we play with values If we try, we 'are not working properly.

We know that we need to use the rotation of the camera as well as its position, but we can not understand the formula to get the world matrix of weapons.

What we have, the position of the camera as a vector 3, the rotation of the camera as vector 3, also with Y coordinate horizontal rotation, between Pi and -Pi, and X vertical Rotation is in the form of. The weapon is extended to 0.1f

Edit: There is some code relative to my problem:

Previous> Public Zero Update () {Weapons . Repeat = This player. Weapon.world metrics = Weaponworld matrix (This player.position, japlayer.open.y, japlayer.open.x); } Private Matrix Weaponworld Metrix (Vector 3 Status, Float Update Down, Float Diet Off) {Vector 3Xxis; Vector 3 yaxis; XAxis.X = View Manager. GameCamera.View.M11; XAxis.Y = View Manager. Game.camera View.m 21; XAxis.Z = View Manager. GameCameraWindowsMM 31; YAxis.X = View Manager. Game.Camera.View.M12; YAxis.Y = View Manager. Game.camera View.m 22; YAxis.Z = View Manager. Game.Camera.View.M32; Position + = new vector 3 (1, 0, 0) / 5; // How far off camera the exploration gun position will be + = xxis * 1f; // X axis offset position + = - Axis * 0.5F; // Y axis offset screen manager. Game.Debug Screen Debug (position.To string ()); Return Matrix Creteskel (0.1 F) // Gun Size * Matrix. Creetfram Yipichol (Mathhaler.Toradians (5), 0, 0) // Rotation Offset * Matrix. Crayertotation X (Update Down) * Matrix. Creation N (left) * Matrix .CreateTranslation (status); }

The easiest way to do this is to change the matrix of the camera Can be used to position position and representation of the camera rotation. This result can be borrowed and can change a bit to become the world's weapon of metrics.

  Matrix CameraWorld = Matrix. Invert (scene); Matrix Weapons World = Camera World; // gives a weapon to its weapon which is co-located and co-rotated with the camera, then simply move the weapon matrix as the necessary weapon. Translation + = (Camera World.Forward * distInFrontOfCam) + set to taste / runs a little weapon in front of the camera (Camera World. Down * zodiac WiaponIsLowedFromCenterOfScreen) + / Bottom from the center of the screen set to taste (Camerworld. Wright takes the weapon in the left or right offsets); // Set for the taste If desired, the weapon moves to the center of the left or right  

Edit I saw that you are also trying to implement the scale of your weapon. Instead of doing this in my suggestion code, right-click on the weapon model in Solution Explorer and choose the properties. On the asset window, click the small arrow next to the 'Content processor' to expand the list. Search scale properties and set scale (your 0.1 F or whatever). In order to scale that model, you no longer need to waste CPU cycles. Due to this it can be determined in the build phase when it converts FBX into XNB.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -