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 /
avatar image
0
Question by efobrog · Oct 07, 2019 at 12:25 PM · instantiatetransformposition

not instantiating at correct transform

i have made a script for a bullet, and when it hits a bird, it instantiates a feather particle system, except the particle system's position is miles away and i don't know why. here's the script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bullet : MonoBehaviour { public float expireRate; private float currentTimer; public GameObject otherPlayer; public float movSpeed; public float damageRate; public GameObject feathers; //public Renderer rend; //public Collider coll; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { this.transform.Translate(Vector3.left * Time.deltaTime * movSpeed); currentTimer += 1 * Time.deltaTime; if (currentTimer > expireRate) Destroy(this.gameObject); } void OnCollisionEnter(Collision col) { if (col.gameObject.tag == "Bird") { //otherPlayer = col.gameObject; Debug.Log("killed-bird"); //Destroy(col.gameObject); //Destroy(gameObject); col.gameObject.GetComponent<Renderer>().enabled = false; //rend.enabled = false; //coll.enabled = false; Instantiate(feathers, col.transform); } Destroy(this.gameObject); } } is there anyway to actually get it to instantiate at the right position? Thanks

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

2 Replies

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

Answer by Kristifor_p · Oct 13, 2019 at 08:19 PM

Here is my solution, i just wrote you a script you need to attach it to your bird, and tag your bullets with the tag "Bullet". Please take a look try it and if you have any problem with setting it up just let me know.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BirdHit : MonoBehaviour
 {
     [Header("Bird Settings:")]
     public GameObject featherParticle; // Put your particle prefab here.
     public AudioClip birdDieSFX; // You could put some sound FX to be played when your bird die.
 
     private bool isHit; // Bool that will control your paticle destruction.
 
     private void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.CompareTag("Bullet"))
         {
             Instantiate(featherParticle, transform.position, Quaternion.identity);
             AudioSource.PlayClipAtPoint(birdDieSFX, transform.position);
             Destroy(gameObject);
 
             isHit = true;
 
             Debug.Log("You hit the bird!");
 
             // This will destroy the particle clone in hierarchy.
             if(isHit)
             {
                 Destroy(featherParticle, 1.0f);
             }
         }
     }
 }



Hope this will help you out @efobrog!

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 efobrog · Jan 03, 2020 at 06:46 AM 0
Share

i didn't use all of it but some parts of the script fixed my problem. I also employed the death sounds :)

sorry i was late for reply, i got lazy with the game

avatar image
1

Answer by WarmedxMints · Oct 07, 2019 at 12:51 PM

If you read the documentation here you will see that the Object.Instantiate method has a few overloads. You are setting its parent, not its position.

You need to pass a vector and rotation to set its position.

Comment
Add comment · Show 3 · 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 efobrog · Oct 08, 2019 at 07:17 AM 0
Share

i know i sound dumb, but how can i do that?

avatar image efobrog · Oct 08, 2019 at 07:36 AM 0
Share

also, is there a way to not instantiate it to a child of the bird?

avatar image efobrog · Oct 13, 2019 at 06:49 AM 0
Share

hello? are you alive?

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

176 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with moving instantiated object's transform 1 Answer

Moving a transform behaves odd 0 Answers

transform position and rotation of instantiated object 1 Answer

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

How can I get a GameObject's transform in game and set that to a variable? 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