Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 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
1
Question by MicDaRoc · Aug 03, 2015 at 01:50 PM · colliderprefabparentparticle systembullet

Particle System emitting at wrong location

Hi! I've got a BulletPrefab with a Particle System attached to it (as child). Hitting the FireButton instatiates clones of my bullet. Everything's working fine so far. I want the Particle System to emit whenever a bullet hits a collider (obstacles, other players and so on) at the exact position where the bullet hits said colliders. This only works for the first time. I start the game, shoot at an enemy1 and the particle effect appears right there where it collides with enemy1. Shooting enemy2 results in the particle effect appearing at the position from enemy1. That is obviously not what I want. I need the particle effect to appear on different locations, exactly there where the Bullet hits an collider.

Here's the code I wrote. It's attached to the BulletPrefab.

 void OnTriggerEnter2D(Collider2D otherCollider){
 
         GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().transform.parent = null;
         GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().Play ();
     }

The bullets are destroyed as soon as they hit a collider and to prevent the destruction of the particle System as well I need to detach it from its parent.

So here's my question: What can I do to move the Particle Systems location to wherever the new instatiated bullet hits a collider?

Thanks in advance! And if you need more information, just let me know.

Comment
Add comment · Show 1
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 OrdinaryDev83 · Aug 03, 2015 at 01:59 PM 0
Share

I anwsering, wait for it.

3 Replies

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

Answer by MicDaRoc · Aug 03, 2015 at 03:17 PM

I've got it!

Instead of having a Particle System as child of the ShotPrefab, I created a Particle System Prefab. In the shotscript (which is attached to the shotPrefab) I wrote this little piece of code:

public GameObject particlePrefab; public Transform shot1;

 void OnTriggerEnter2D(Collider2D otherCollider){
 
         
 Instantiate( particlePrefab, shot1.position, shot1.rotation);
 
 
     }

In the Inspector just assign shot1 as your bullet Prefab and there you go. Thanks Bryckout for the help! Two thumps up!

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

Answer by OrdinaryDev83 · Aug 03, 2015 at 02:10 PM

Attach this to bullet prefab:

 var ps : GameObject;
 
 function Update(){
      var hit : RaycastHit2D;
      var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      if(Physics.Raycast2D(ray,hit){
           var go = Instantiate(ps,hit.position,hit.rotation);
           Destroy(this.gameObject);
      }
 }


Next create a prefab for particles. Attach this to particlePrefab:

 function Update(){
      if(!this.GetComponent(ParticleSystem).IsAlive){
           Destroy(this.gameObject);
      }
 }

Not tested, Have fun.

Comment
Add comment · Show 4 · 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 MicDaRoc · Aug 03, 2015 at 02:36 PM 0
Share

Thanks for your answer. Where and how do I call the particlePrefab?

avatar image OrdinaryDev83 · Aug 03, 2015 at 02:44 PM 0
Share

Give me you "shooting" script please, if you have one.

avatar image MicDaRoc · Aug 03, 2015 at 02:48 PM 0
Share
 if (Input.GetButton ("Fire_P" + animString) && Time.time > nextFire) {
                 nextFire = Time.time + fireRate;
                 InstantiatedObj = (GameObject)Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
                 InstantiatedObj.GetComponent<ShotScript> ().PlayerOwner = this.gameObject;
                 Destroy (InstantiatedObj, 3f);

avatar image OrdinaryDev83 · Aug 03, 2015 at 03:51 PM 0
Share
 var bulletPrefab : GameObject; //The bullet prefab
 
 if (Input.GetButton ("Fire_P" + animString) && Time.time > nextFire) {
                  nextFire = Time.time + fireRate;
                  InstantiatedObj = Instantiate (bulletPrefab, shotSpawn.position, shotSpawn.rotation);
 }

Try this :) with script and instruction i gave to you.

avatar image
0

Answer by ramiz291 · Aug 15, 2021 at 12:53 PM

Please check your particle system simulation space. If it is attached as a child, make it local instead of world. alt text


ps.png (5.5 kB)
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

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

24 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

Related Questions

Make a simple tree 1 Answer

Trouble with triggers and colliders 1 Answer

My object acts wierd, 2 balls being shot instead of one (from different position) 2 Answers

onParticleCollison not triggering 0 Answers

collision.gameObject returning parent. 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