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 /
avatar image
0
Question by eric gemmell · Aug 22, 2014 at 05:54 PM · colliderparticles

how to know if an object has been englobed by particles

I am working on a game, in this game you are a 2d particle,the objective is to get to the end of the level, to get there you must kill all the bad guys on the way. To kill you must englobe them with a trail of particles that you leave behind wherever you go and that fade over time. The thing is that i am rather a noob with particles an englobing object with them and i have really no clue to how to do this code. I was thinking of creating a number of 2d edge colliders in between each successive particle and then checking if i have gone through one of them each frame, and if i have i would make my mad guy send an ray through a random location and if it goes through one of those a pair number of times it is then outside of the englobed area otherwise it is inside. That was the idea i had in mind although i think to be extremely complicated. Any advice on how to this would be more than gratified. 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 22, 2014 at 06:16 PM

The code will depend on what you mean by englobed, and how literally you want to interpret the term. First lets say we only consider a particle as participating in the englobing of an object if they are within some defined distance. Second, we consider an object englobed if there are a defined number of 'participating' particles in front and behind the object.

As a concrete example say our enemy/object was about 1 unit on a side, and we only consider particles participating if they are within 1.5 units of the pivot of the enemy/object. And we need 10 participating particles in front and 10 participating particles behind the enemy/object to consider it englobed.

  • The code that need to do the englobing calculation needs to get access to the particle system. If this is a problem for you, search out answers on accessing components on other game objects.

  • Each frame from the particle system, you will get the particles. Carefully search out how to do this since it is not like the other places in Unity where you get an array. You have to first create an array the size of MaxParticles, then you need to pass that array in to GetParticles() and include the size. Also, assuming you are using the ParticleSystem, the type will be ParticleSystem.Particle[].

  • For each particle in the array, you first check the distance between them to see if it is participating. Since this is 2D, you can use Vector2.Distance(), but since the ParticleSystem.Particle.position is a 3D as is the position of the enemy/object, you'll have to cast the parameters to Vector2s.

  • For all particles that are within the specified distance, you'll check the 'x' position relative to the 'x' position of the enemy/object. If it is less, then you increment a variable for one side, if it is more you increment a variable for the other.

  • If at any time the two variables (one representing each side of the object) are both over the threshold value, then the enemy/object is englobed.

Comment
Add comment · Show 11 · 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 eric gemmell · Aug 22, 2014 at 06:33 PM 0
Share

First of all thank you Robertbu for your answer, by englobe i mean form a circle around the enemy, in such a way that it is surrounded by the particles(by the way i forgot to say that the particles are not moving). Judging by the way you would do this code do you think it would be far to hard to do the surrounded enemy check?

avatar image eric gemmell · Aug 22, 2014 at 06:45 PM 0
Share

I think i might have an idea, what if each enemy had a set of children, and each one had a box collider attached to it. these children would themselves be placed around the enemy in such a way that when you go inside one of those colliders they would send a message to the bad guy that you have entered. if all the children send this message in a given time then we would consider the enemy surrounded. If one would want more detailed surround effect they would only need to increment the number of children.

avatar image robertbu · Aug 22, 2014 at 07:02 PM 0
Share

Colliders don't receive collisions from particles. While I don't know for sure, I don't believe particles interact with 2D colliders. One post mentioned that it was planned for some future release. For particle collisions, you have to listen for OnParticleCollision() callback on a script on the same game object as the ParticleSystem. Then you have to retrieve a list of the collisions. Given the 3D requirement, I don't believe listening to collisions will work for you.

You could use angle to check 8 separate positions. Have a boolean array of size 8 called 'directions' where all the values start at false. For each particle you can do:

 var dir = particle.position - object.position;
 var angle = $$anonymous$$athf.Atan2(dir.y, dir.x) * $$anonymous$$athf.Rad2Deg;
 var i : int = $$anonymous$$athf.RoundToInt(angle / 45.0);
 var i = i % 8;
 directions[i] = true;

If after processing all the particles, all the values in 'directions' are true, then the object is surrounded.

avatar image eric gemmell · Aug 22, 2014 at 07:16 PM 0
Share

3d collisions is no issue i think no?

avatar image robertbu · Aug 22, 2014 at 07:26 PM 0
Share

The problem with a 3D collision is they only occur on a surface and only on the front of that surface. Say you placed a sphere or a box at each of the eight points. If the particle was inside the box, it would not be detected. And again, it won't be the 3D object that detects the collision, it will be the ParticleSystem using OnParticleCollision()>

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

particle colliders 1 Answer

Using different paricle emitters depending on the tag of the object raycast hits? 1 Answer

Make collider behave like a trigger without isTrigger 1 Answer

Internal collisions 1 Answer

Problem with ParticleSystem Colission 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