- Home /
FPS Gun Attached To Camera Weirdness
Hello there! I have been having a problem lately with all of my Unity FPS projects. When I attach a gun to my main camera and look up, the gun moves up too much. This also happens when I look down. No scripts attached to the gun. I'll show you some pictures. Please help!!
I think its because your gun is quite long maybe?Try using a model ins$$anonymous$$d of a capsule.It would make things easier to see.
The same thing happens with pistols, and the game is single player, so a model for the player would just add lag.
Answer by welwiz1 · Oct 19, 2016 at 09:03 PM
just so people know, all you have to do is make your players scale the same in all axis and it fixes this problem
Answer by brabbani · Dec 28, 2015 at 02:11 PM
The question is quite very old but I stuck up with the exact same problem and my issue was appeared because I changed the Scale-Y value in Transform of inspector of Player (First Person Controller), from 1 to 1.5. When I revert it to Scale-> 1, 1, 1 then everything start working fine.
Answer by Anti-Social Fred · Jul 15, 2014 at 03:46 PM
If it's moving up and down too much, then the only solution is to dampen the rotation. You CAN still maintain the relationship between parent-child / camera-weapon, but I would prefer doing something more along the lines of creating a separate script to manage rotation based off of the Camera.main.transform.rotation / eulerAngles, and unparenting the weapon completely.
The finished code should look something like:
private Transform _cameraTransform = null; // Caches the Camera's transform.
GameObject _currentWeapon = null; // Current weapon that's being used
Transform _playerTransform = null; // Player's Transform
bool _canRotateWeapon = true; // Can you rotate the weapon?
float _rotationDampener = 0.5F; // The amount that you want to multiply the rotation by. If it's rotating too much, keep this number < 1
void Start()
{
_cameraTransform = Camera.main.transform;
}
void Update()
{
UpdateWeaponRotation();
}
// Updates the weapon's rotation
void UpdateWeaponRotation()
{
if (_canRotateWeapon && _currentWeapon != null) // If there's currently a weapon and you can rotate the weapon
{
Vector3 desiredRotation = new Vector3(_cameraTransform.eulerAngles.x * _rotationDampener, _playerTransform.eulerAngles.y, _playerTransform.eulerAngles.z); // Sets the rotation based off of the dampener * the Camera's X-axis. It might be the Z-axis instead so... don't get fully invested in using the X
_playerTransform.eulerAngles = desiredRotation; // Set the eulerAngles.
}
}
I added it to the comments, but you may require the Z-axis instead of the X-axis, based on your local rotation of the weapon. Heck, maybe even the Y-axis. Just mess around with it.
Your answer
Follow this Question
Related Questions
Fps Arm moves fase 2 Answers
FPS (sometimes) invisible gun?! 2 Answers
I want to change gun position with my camera joystick 0 Answers
How to bring reticles in different situations to the center of the camera? 0 Answers
Problem with camera and gun in FPS game 0 Answers