Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by Razputin · Mar 30, 2018 at 10:47 PM · collisionparticlescollision detectionparticlesystem

OnParticleCollision Question (Image included) Particle Decal Hanging off Edge

I want to be able to tell if where the particle hits is within the bounds of the object it hit subtracted by the max size of the splatter that will be displayed on the hit object. This way if the splatter is hanging off the edge of the hit object it can be destroyed instead. But it doesn't seem like its possible to determine where OnParticleCollision hit outside of worldspace. Does anyone know of a way I can tell where the collision occurred relative to the object that the particle collided with.

If that doesn't make sense then does anyone know another way to detect and remove particle decals when they're hanging off the edge of an object.

Here is an image of what I'm talking about : https://i.imgur.com/HUYKXvB.png

I am using the following system slightly modified for my Splatter effect so you can view the code here: https://unity3d.com/learn/tutorials/topics/scripting/drawing-decals-particles

I don't want to do anything fancy like wrapping it or moving it. Just destroying / not spawning it is fine.

     void OnParticleCollision(GameObject other)
     {
         ParticlePhysicsExtensions.GetCollisionEvents(particleLauncher, other, collisionEvents);
 
         for (int i = 0; i < collisionEvents.Count; i++)
         {
             //The if statement would probably go here 
             splatDecalPool.ParticleHit(collisionEvents[i], particleColorGradient);
             EmitAtLocation(collisionEvents[i]);
         }
     }
 

Thank you!

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

Answer by Razputin · Apr 01, 2018 at 10:57 PM

Alright I ended up adding a transform to the ParticleDecalData, spawning an empty gameobject on the point of collision then setting the empty gameobjects size/rotation/position equal to that of the particle image, then taking that transform and filling it in to the particledecaldata transform. Then firing a raycast opposite of whichever way the transform was pointing on all 4 sides. If all 4 sides collide with something, it means they're all touching the wall and the image can be displayed without any edges hanging off. Otherwise I just shrink the image to a size of 0 so it can't be seen.

  void SetParticleData(ParticleCollisionEvent particleCollisionEvent, Gradient colorGradient)
     {
         if(particleDecalDataIndex >= maxDecals)
         {
             particleDecalDataIndex = 0;
         }
         particleData[particleDecalDataIndex].position = particleCollisionEvent.intersection;
         Vector3 particleRotationEuler = Quaternion.LookRotation(particleCollisionEvent.normal).eulerAngles;
         //particleRotationEuler.z = Random.Range(0, 360);
         particleData[particleDecalDataIndex].rotation = particleRotationEuler;
         particleData[particleDecalDataIndex].size = Random.Range(decalSizeMin, decalSizeMax);
         particleData[particleDecalDataIndex].color = colorGradient.Evaluate(Random.Range(0f, 1f));
         GameObject temp = new GameObject();
         particleData[particleDecalDataIndex].transform = temp.transform;
         particleData[particleDecalDataIndex].transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
         particleData[particleDecalDataIndex].transform.position = particleData[particleDecalDataIndex].position;
         particleData[particleDecalDataIndex].transform.localScale = new Vector3(particleData[particleDecalDataIndex].size, particleData[particleDecalDataIndex].size, particleData[particleDecalDataIndex].size);
         Debug.Log(particleData[particleDecalDataIndex].transform.localScale);
         Destroy(temp);
         CheckRaycast(particleDecalDataIndex);
         particleDecalDataIndex++;
     }


 
     void CheckRaycast(int particleDecalDataIndex)
     {
         float size = particleData[particleDecalDataIndex].size / 2;
         Vector3 fwd = particleData[particleDecalDataIndex].transform.forward;
        
         if (Physics.Raycast(new Vector3(particleData[particleDecalDataIndex].position.x - size, particleData[particleDecalDataIndex].position.y, particleData[particleDecalDataIndex].position.z), -fwd, 2, mask)
             && Physics.Raycast(new Vector3(particleData[particleDecalDataIndex].position.x + size, particleData[particleDecalDataIndex].position.y, particleData[particleDecalDataIndex].position.z), -fwd, 2, mask)
             && Physics.Raycast(new Vector3(particleData[particleDecalDataIndex].position.x, particleData[particleDecalDataIndex].position.y, particleData[particleDecalDataIndex].position.z - size), -fwd, 2, mask)
             && Physics.Raycast(new Vector3(particleData[particleDecalDataIndex].position.x, particleData[particleDecalDataIndex].position.y, particleData[particleDecalDataIndex].position.z + size), -fwd, 2, mask)
             )
         {
             Debug.Log("Touching All Points");
         }
         else
         {
             Debug.Log("Missing");
             particleData[particleDecalDataIndex].size = 0;
         }
     }

If anyone can think of a better solution that'd be great though.

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

126 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

Related Questions

OnCollisionExit for Particles 0 Answers

is it possible to detect the Particle Collision from another gameobject like a normal collision ? 2 Answers

Transforming and playing particle effects? Help! 1 Answer

How do I detect world particle collisions in Unity4.0? 0 Answers

[2D] Getting particles to collide with a game object(Explosion debris effect) 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