Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 16, 2014 at 06:02 PM by z3nth10n for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by z3nth10n · Jan 26, 2014 at 12:21 PM · gameobjectinstantiatepositionbulletwrong

GameObject Instantiated in Wrong Position

Hi,

I'm making a gun system, and when I click I instantiate a bullet with the player position, the problem is that:

Buller position problem

 //BulletScript attached to the bullet Gameobject
 
 using UnityEngine;
 using System.Collections;
 
 public class BulletScript : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         float x = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.x+3;
         float y = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.y;
         float z = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.z+3;
         transform.position = new Vector3(x, y, z);
     }
     
     // Update is called once per frame
     void Update () {
         transform.rigidbody.AddForce(transform.eulerAngles*10);
     }
 }

And the second script:

 //GunScript attached to the Inventory Item (it's a MP5)
 
 using UnityEngine;
 using System.Collections;
 
 public class GunScript : MonoBehaviour {
 
     GameObject bullet;
     
     // Use this for initialization
     void Start () {
         if(Input.GetMouseButtonDown(0)) { //This is weird because I have to use it in the Start void, and not in the Update
             bullet = GameObject.Instantiate(Resources.Load("Models/Items/Bullets/bala"), GameObject.Find("Player").transform.FindChild("mainCam").transform.position, GameObject.Find("Player").transform.FindChild("mainCam").transform.rotation) as GameObject;
         }
     }
     
     // Update is called once per frame
     void Update () {
 
     }
     
 }
 


How can I solve that?

Thanks in advance. Bye.

Comment
Add comment · Show 11
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 Armored13 · Jan 26, 2014 at 12:29 PM 0
Share

Could you show us some of the code? There are a number of reasons the bullet could be getting placed incorrectly.

avatar image z3nth10n · Jan 26, 2014 at 01:07 PM 0
Share

Ok, sorry, I updated the question... :P

avatar image Reiv · Jan 26, 2014 at 01:42 PM 0
Share

Your player isn't inside another empty game object?

avatar image z3nth10n · Jan 26, 2014 at 02:39 PM 0
Share

$$anonymous$$y player doesn't have any parent...

avatar image Sundar · Jan 26, 2014 at 08:07 PM 0
Share

Comment out bulletscript Update() then check bullet's position (as you are applying force on it the moment it instantiated. Fire bullet only when fire is clicked.)

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by z3nth10n · Mar 16, 2014 at 06:02 PM

Hi,

I solved it sometime ago, but It's only a reminder, don't put anytime a rigidbody with a mesh collider together...

Bye.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

20 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

Related Questions

GameObject change Position after game started 1 Answer

Instantiate as a child at position 2 Answers

How to implement a system for "Road-Construction"? 1 Answer

Instantiate a GameObject at a position specific to an element that was found in a text 1 Answer

Adjacent Placement of Objects according to varying height 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