Ok so this is my first question I’ve posted. I’m trying to do a quick build of a first person shooter to get a functioning product done as I haven’t really finished anything. So I’m not focussing too much on quality as that’s what gets me caught up in production.
Anyway my problem:
So it’s sort of two part. My first problem, which won’t exactly be a problem later, but it could be: I made guns out of cubes to start coding, and so I didn’t have to sit and code a holding block I just made it a child of my camera, and positioned it at the hold position. This is working fine but for some reason when I look up and down the gun warps weirdly. I’ll try to attach some screenshots.
The next problem is I’ve written a block of code for switching guns. It works perfect for certain guns, but once I get to the first gun I’ve made it runs the DropGun() function on the gun I’m trying to pick up and keeps the one I already have. Also when I continuously try to pick up the gun, it warps them also. I’ve also found it’s when I have my camera faced down where the gun I’m holding is warped. Any help would be greatly appreciated. I’m not a beginner to coding or using unity (however I wouldn’t say I’m a strong coder), but this is a problem I can’t figure out. This will help me learn a bunch.
here are the picking up and dropping functions Let me know if you need to see any other code:
void Pickup()
{
if (pControl.currentGun != null)
{
Firearm arm;
arm = pControl.currentGun.GetComponent();
arm.DropGun();
}
Debug.Log("I'm getting picked up");
gameObject.transform.parent = cam;
body.isKinematic = true;
body.useGravity = false;
collider.enabled = false;
transform.localPosition = holdPosition;
transform.localRotation = Quaternion.identity;
isHeld = true;
pControl.currentGun = gameObject;
}
public void DropGun()
{
gameObject.transform.parent = null;
body.isKinematic = false;
body.useGravity = true;
collider.enabled = true;
body.AddForce(Player.transform.forward * throwPower);
isHeld = false;
}