playMaker

Author Topic: Detect a collision with any surface  (Read 773 times)

stigma

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Detect a collision with any surface
« on: July 10, 2019, 09:02:10 AM »
Hello,
Is it possible to detect the collision of a GameObject with any surface?
For example, I want to trigger a script if an object falls into the water.
Thank you

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Detect a collision with any surface
« Reply #1 on: July 10, 2019, 09:37:55 AM »
Yes. This is very straight forward, but the exact method may vary by what you want to achieve / what you need to work around, etc.

See the manual for Trigger Event: https://hutonggames.fogbugz.com/?W37

So for example, you could have your water tagged (part of Unity, not Playmaker specifically) as a name ("water" for example) and so when your trigger hit an object with that tag it goes to the next event.

stigma

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Detect a collision with any surface
« Reply #2 on: July 10, 2019, 02:26:46 PM »
it does not work.
I want to push an object in the water and it should float by triggering the script.

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Detect a collision with any surface
« Reply #3 on: July 10, 2019, 08:29:16 PM »
Collisions are handled by Unity Collider modules; Box Collider, Capsule Collider, Sphere Collider or Mesh Collider
See here: https://docs.unity3d.com/Manual/CollidersOverview.html

I'm having a hard time judging what level you are on and what you need to know or not. I don't know if you need to maybe watch a YouTube tutorial on colliders and setting them to triggers or not.

Basically the collider is the way you can bump in to something. If the object has a collider and a Rigidbody, you will be able to push it (if it's not set to kinematic). You use that regular collider and add a second collider which is a little larger (so it will be hit before the one used to push the object), with the second one set to be a Trigger. This means the second collider is a like a ghost you can pass through, but you can use it to register if something Enters, Exits, or Stays in that trigger.

As mentioned previously, you do this via the Trigger Event action. You set what object you are watching, if it's enter, stay, or exit, and then also (for your case) set what Tag the other colliding object must have to be valid.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15398
  • Official Playmaker Support
    • View Profile
Re: Detect a collision with any surface
« Reply #4 on: July 10, 2019, 11:50:59 PM »
Hi,

 Buoyancy is a very unique physic interaction that is not really supported by default with Unity physics ( apart from the 2d which has an effector for this: https://docs.unity3d.com/Manual/class-BuoyancyEffector2D.html) ,in 3d, you need a lot of work to get there. Which is why I would strongly recommand using an asset for this like:

https://assetstore.unity.com/packages/tools/physics/fast-buoyancy-61079

you also have many more advanced systems as well like:

https://assetstore.unity.com/packages/tools/physics/dynamic-water-physics-2-147990

 Bye,

 Jean

stigma

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Detect a collision with any surface
« Reply #5 on: July 11, 2019, 08:44:33 AM »
I did something that works by comparing the altitude of the object with the sea.
Is it ok, given that I have a lot of objects that can float?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15398
  • Official Playmaker Support
    • View Profile
Re: Detect a collision with any surface
« Reply #6 on: July 12, 2019, 12:28:11 AM »
Hi,

 It should be ok yes. Make sure to run the profiler to monitor that it doesn't take up too much of your perfs just for this.

 Bye,

 Jean