• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by awplays49 · Feb 20, 2015 at 07:10 PM · modelgooglelinkreimportdrive

*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.

Comment

People who like this

0 Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image awplays49 · Feb 20, 2015 at 07:53 PM 0
Share

Also sorry for having to resort to asking but I really need a second pair of eyes.

avatar image Mmmpies · Feb 20, 2015 at 08:23 PM 0
Share

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.

avatar image awplays49 · Feb 20, 2015 at 08:35 PM 0
Share

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 : MonoBehaviour {
 
     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 OnMouseDown () {
         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);
     }
 }


avatar image Kiwasi · Feb 20, 2015 at 08:42 PM 0
Share

You could have put up a project that doesn't require modification to run. Grumble, grumble... Off to fix the compile errors.

avatar image awplays49 · Feb 20, 2015 at 08:43 PM 0
Share

I didn't realize there was errors

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Kiwasi · Feb 20, 2015 at 08:49 PM

Remove the rigidbody off of the pistol. Game then behaves fine.

Comment
karljj1

People who like this

1 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image awplays49 · Feb 20, 2015 at 08:51 PM 0
Share

It was the rigidbody? Thanks man!

One more thing, what code can i add to this

 using UnityEngine;
 using System.Collections;
 
 public class Gun : MonoBehaviour {
 
     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 OnMouseDown () {
         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.

avatar image Kiwasi · Feb 20, 2015 at 09:16 PM 1
Share

Rigid bodies can't be disabled. You can set isKinematic to true, which should also work.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Upload/Download .txt files from Google Drive in Unity 3 Answers

Google Sketchup models appearing badly 2 Answers

Google Drive Plugin - full access from android device 1 Answer

Reimport destroyed .obj file submeshes? 0 Answers

I want to load object from my computer or google drive. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges