- Home /
*still unanswered* Game moving gun after pausing
Hi i reimported a model and changed a few things and now when i pause it offsets the gun. I have no idea what i did ive been looking at it for hours and still nothing.
the project: https://drive.google.com/file/d/0B2ZiQtohl3tmRTBGSm5qWGxNNkU/view?usp=sharing
the gun code is a little broken. im trying to make it so that if the starter gun checkbox is true, put the gun in his hand and parent it to the wrist.
Also sorry for having to resort to asking but I really need a second pair of eyes.
Blimey @awplays49 what you done there!
Try jumping or going up a hill as well!
Which script do you use to place the gun in the hand as I think you've got that wrong, really the gun should match the transform of the hand even if you jump. The really odd thing is it matches the animation of the hands fine but I don't think it sets the transform correctly as it glitches as you say and refuses to move when jumping.
Yea so weird. i parented it in start method. check the gun script maybe @mmmpies
EDIT:
Heres the script in case you can find it:
using UnityEngine;
using System.Collections;
public class Gun : $$anonymous$$onoBehaviour {
public GameObject Weapon1Get;
public GameObject Weapon2Get;
private GameObject LastWeapon;
public GameObject PlayerGet;
public int SpawnHeight;
public int FallForce;
private Vector3 SwitchPos;
public bool IsStarterGun;
void Start () {
Physics.IgnoreCollision (collider, PlayerGet.collider, true);
if (IsStarterGun == true)
{
transform.position = Weapon1Get.transform.position;
transform.rotation = Weapon1Get.transform.rotation;
transform.parent = Weapon1Get.transform;
rigidbody.useGravity = false;
}
}
void On$$anonymous$$ouseDown () {
LastWeapon = Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon;
LastWeapon.transform.parent = LastWeapon.transform;
SwitchPos = transform.position;
transform.position = Weapon1Get.transform.position;
transform.rotation = Weapon1Get.transform.rotation;
transform.parent = Weapon1Get.transform;
rigidbody.useGravity = false;
LastWeapon.transform.position = new Vector3 (SwitchPos.x, SwitchPos.y + SpawnHeight, SwitchPos.z);
LastWeapon.rigidbody.useGravity = true;
rigidbody.detectCollisions = true;
LastWeapon.rigidbody.velocity = new Vector3 (0, -FallForce, 0);
}
}
You could have put up a project that doesn't require modification to run. Grumble, grumble... Off to fix the compile errors.
Answer by Kiwasi · Feb 20, 2015 at 08:49 PM
Remove the rigidbody off of the pistol. Game then behaves fine.
It was the rigidbody? Thanks man!
One more thing, what code can i add to this
using UnityEngine;
using System.Collections;
public class Gun : $$anonymous$$onoBehaviour {
public GameObject Weapon1Get;
public GameObject Weapon2Get;
private GameObject LastWeapon;
public GameObject PlayerGet;
public int SpawnHeight;
public int FallForce;
private Vector3 SwitchPos;
public bool IsStarterGun;
void Start () {
Physics.IgnoreCollision (collider, PlayerGet.collider, true);
if (IsStarterGun == true)
{
transform.position = Weapon1Get.transform.position;
transform.rotation = Weapon1Get.transform.rotation;
transform.parent = Weapon1Get.transform;
rigidbody.useGravity = false;
}
}
void On$$anonymous$$ouseDown () {
LastWeapon = Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon;
LastWeapon.transform.parent = LastWeapon.transform;
SwitchPos = transform.position;
transform.position = Weapon1Get.transform.position;
transform.rotation = Weapon1Get.transform.rotation;
transform.parent = Weapon1Get.transform;
rigidbody.useGravity = false;
LastWeapon.transform.position = new Vector3 (SwitchPos.x, SwitchPos.y + SpawnHeight, SwitchPos.z);
LastWeapon.rigidbody.useGravity = true;
rigidbody.detectCollisions = true;
LastWeapon.rigidbody.velocity = new Vector3 (0, -FallForce, 0);
}
}
to just disable the rigidbody when its in the players hand? I thought the code would do that.
Rigid bodies can't be disabled. You can set is$$anonymous$$inematic to true, which should also work.