Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by sxnorthrop · Mar 29, 2016 at 07:37 PM · instantiatepositionspawningbonesincorrect

Instantiate not working correctly (Please help!)

So in this particular game I'm using LateUpdate() to set the position of the players spine, and attached to the players hand is a weapon, under the weapon I have Transforms set up as spawn points that are used for prefab instantiation. Here's the bit of code showing the instantiation.

 void SpawnShell () {
         if (shellPrefab == null)
             return;
         
         if (shellSpawn == null) {
             Debug.Log ("Weapon::SpawnWeaponEffects -- For the shell to spawn you need to fill in the 'shellSpawn' slot.");
             return;
         }
 
         if (shellPrefab.GetComponent<Rigidbody> () == null) {
             Debug.LogError ("Weapon::SpawnShell -- For the shell to spawn you need a rigidbody component attached.");
             return;
         }
 
         GameObject shell = (GameObject)SimplePool.Spawn (shellPrefab, shellSpawn.position, shellSpawn.rotation);
         Rigidbody srb = shell.GetComponent<Rigidbody> ();
         // FIXME: Hardcode.
         srb.AddForce (shellSpawn.forward * Random.Range (1, 3), ForceMode.Impulse);
     }

This get's called when the player hit's the Fire1 button. Here's that code...

 if (aiming) {
             if (Input.GetButtonDown ("Fire1")) {
                 FireWeapon (new Ray(cameraRig.mainCamera.transform.position, cameraRig.mainCamera.transform.forward));
             }
         }

The FireWeapon function calls to the weapon and tells it to call the Fire() function, which then spawns the prefabs.

The problem is impossible for me to figure out and here's a picture showing the setup: alt text

And as you can see the transform is a child. And in another script I have the spine rotating in late update:

 Ray aimRay = new Ray(cameraRig.mainCamera.transform.position, cameraRig.mainCamera.transform.forward);
                 Vector3 lookPos = aimRay.GetPoint (50);
                 spine.LookAt(lookPos);
                 spine.Rotate (spineOffset, Space.Self);
                 Debug.Log (currentWeapon.transform.position);


But when the object spawns it spawns at the position that the gun is when im not aiming. even though I look down (it will spawn as if I'm looking straight forward) I really hope you guys can help me.

untitled2.png (389.4 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sxnorthrop · Mar 29, 2016 at 07:38 PM

And the simple pool is just basically instantiating these objects and putting them into a pool.

Comment
Add comment · Show 1 · 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 sxnorthrop · Mar 31, 2016 at 04:29 PM 0
Share

Solved this by moving the code: if (Input.GetButtonDown ("Fire1"))into late update

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.

Follow this Question

Answers Answers and Comments

57 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 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 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

Problem with instantiated prefabs. Object stays dark 1 Answer

Make a gameobject spawn before enemies spawn? (C#) 1 Answer

How to store a position that is moving to create a prefab to spawn at the exact position 1 Answer

Instantiate prefab if no prefab exists at location 1 Answer

Instantiated prefab trying to keep weird Y position 0 Answers


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