playMaker

Author Topic: Unity 2D and Physics 2D Support now available  (Read 39758 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity 2D and Physics 2D Support now available
« Reply #30 on: December 16, 2013, 06:31:04 AM »
Hi,

 Good catch, please redownload from the wiki page,

Thanks,

 Jean

cloud03

  • Full Member
  • ***
  • Posts: 249
  • Viva Playmaker!
    • Milkish Game Studios Blog
Re: Unity 2D and Physics 2D Support now available
« Reply #31 on: December 19, 2013, 06:21:35 AM »
Here is what I do, the robot shoots arrowIcon when fire1 pressed, and the robot have different tag with the arrowIcon, for the Crate Object, I created a FSM that listening for collision on the first state (first state does not contain any action at all), with Transition Collision enter 2D, when any object collides with the crate, it will automatically activate that transition.

On the second state, the first action will store the game Object that hits the crate, and we will check if that game object have certain tag that we're testing, if its true, then go to destroy, else it will go to Don't destroy transition. I've tested it, and it works, the crate only can be destroyed if its collides with arrowIcon, if I try to move the robot to collide the crate, it will not be destroyed.

hope this helps (I've attached the FSM for the crate)

Just curious here;
I see you have a character made with body parts and hopefully animated with Unity (?).
Have you managed to drive the animations you've made in Playmaker?

I've tested and it works, apparently you can create 2d animation in 4.3, and drive it with playmaker, just follow the step Jean posted (thanks to Lea Hayes):

http://hutonggames.com/playmakerforum/index.php?topic=3186.msg28121#msg28121

funshark

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Unity 2D and Physics 2D Support now available
« Reply #32 on: December 19, 2013, 07:07:12 AM »
Here is what I do, the robot shoots arrowIcon when fire1 pressed, and the robot have different tag with the arrowIcon, for the Crate Object, I created a FSM that listening for collision on the first state (first state does not contain any action at all), with Transition Collision enter 2D, when any object collides with the crate, it will automatically activate that transition.

On the second state, the first action will store the game Object that hits the crate, and we will check if that game object have certain tag that we're testing, if its true, then go to destroy, else it will go to Don't destroy transition. I've tested it, and it works, the crate only can be destroyed if its collides with arrowIcon, if I try to move the robot to collide the crate, it will not be destroyed.

hope this helps (I've attached the FSM for the crate)

Just curious here;
I see you have a character made with body parts and hopefully animated with Unity (?).
Have you managed to drive the animations you've made in Playmaker?

I've tested and it works, apparently you can create 2d animation in 4.3, and drive it with playmaker, just follow the step Jean posted (thanks to Lea Hayes):

http://hutonggames.com/playmakerforum/index.php?topic=3186.msg28121#msg28121

Yes, you can create hierarchical animations that way, but not Sprite animation

cloud03

  • Full Member
  • ***
  • Posts: 249
  • Viva Playmaker!
    • Milkish Game Studios Blog
Re: Unity 2D and Physics 2D Support now available
« Reply #33 on: December 19, 2013, 08:19:07 PM »
Owh, okay, just tested with sprite animation, and it is not working....the robot in my example was created using hierarchical animation, so I thought you we're asking about that one...

funshark

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Unity 2D and Physics 2D Support now available
« Reply #34 on: December 19, 2013, 08:22:51 PM »
Yes, I was asking about that one and at this moment, I didn't know we were able to create legacy animations :)

But now it's fine, all works perfectly (as far I've tested ) with the mecanim update for playmaker :)

cloud03

  • Full Member
  • ***
  • Posts: 249
  • Viva Playmaker!
    • Milkish Game Studios Blog
Re: Unity 2D and Physics 2D Support now available
« Reply #35 on: December 19, 2013, 08:31:43 PM »
Hahahah yup, just check another thread, and there is the surprise, the new animator package for 4.3....

Cheers for Jean, Alex and the whole Playmaker guys for the awesome tools!!!

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
Re: Unity 2D and Physics 2D Support now available
« Reply #36 on: December 26, 2013, 05:58:21 PM »
Hi Jean,

I think there is an error in the Unity documentation for RaycastHit2D.fraction which means the hit distance output gets incorrect results.
They seem to assume input distance = 1 in their writing.
In my experience you have to multiply the hit.fraction by the input distance to get an accurate result, even when using a normalized direction vector.

So it should be:

Quote
storeHitDistance.Value = hitInfo.fraction * rayLength;

« Last Edit: December 26, 2013, 06:02:41 PM by dasbin »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity 2D and Physics 2D Support now available
« Reply #37 on: December 27, 2013, 05:46:05 AM »
Hi,

 I think it's simply because my direction is normalized actually. I'll double check on this. Are you able to verify this properly with testing?

Quote
If the ray's direction vector is normalised then this value is simply the distance between the origin and the hit point

I am on that case, the direction I pass is normalized.

bye,

 Jean

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
Re: Unity 2D and Physics 2D Support now available
« Reply #38 on: December 27, 2013, 05:13:02 PM »
Yes, I know, the problem from what I can see is that that statement (which is from the Unity documentation) is actually wrong. In reality it seems to always pass the hit distance as a fraction of the total ray length (not as a fraction of the magnitude of the input direction as the documentation implies).
So if your input ray distance is 10, and the ray hits something at 5, fraction will return 0.5 even though your input direction vector is normalized. So you always have to multiply the result by the input distance to get an actual hit distance.

My suspicion is that the documentation may be based on some pre-release version of the function where there was no input distance (and distance was instead taken from the magnitude of the direction vector).

Right now your action always gives a "distance" result between 0...1 which is incorrect for any ray length /= 1.
« Last Edit: December 27, 2013, 07:15:53 PM by dasbin »

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
Re: Unity 2D and Physics 2D Support now available
« Reply #39 on: December 27, 2013, 10:16:16 PM »
This will make fixing the GetRayCastHit2dInfo action kind of difficult because it can't just store the RaycastHit2D - it also needs to store a reference to the input distance float separately so that can be factored into getting the distance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity 2D and Physics 2D Support now available
« Reply #40 on: December 28, 2013, 02:48:09 AM »
Hi,

 Ok, thanks for the clarfication, I'll run a proper test on this and update accordingly, I will add a new convenient float that will give the expected result to avoid the user having to do that fraction/raylenght dance...

also, always take the time to report documentation issues to Unity, It must be so hard for them to keep up with everything, so if you can pin point problems so that have it in their database will help get that done quicker. In their bug report, they have a section  for Documentation.


bye,

 Jean

Phillament

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Unity 2D and Physics 2D Support now available
« Reply #41 on: January 29, 2014, 04:34:25 AM »
I'm getting this error, and I didn't have it at all, before. How can I fix this?

Quote
NullReferenceException: Object reference not set to an instance of an object
PlayMakerUnity2d.OnLevelWasLoaded (Int32 level) (at Assets/Assets/PlayMaker Unity 2D/Scripts/PlayMakerUnity2d.cs:89)

NullReferenceException: Object reference not set to an instance of an object
PlayMakerUnity2DProxy.OnTriggerEnter2D (UnityEngine.Collider2D coll) (at Assets/Assets/PlayMaker Unity 2D/Components/PlayMakerUnity2DProxy.cs:159)
« Last Edit: January 29, 2014, 04:54:04 AM by Phillament »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity 2D and Physics 2D Support now available
« Reply #42 on: January 30, 2014, 05:06:58 AM »
Hi,

 You need that proxy on all your scenes, OR make it not destroyable on level load.

Is that the case?

bye,

 Jean

Phillament

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Unity 2D and Physics 2D Support now available
« Reply #43 on: January 30, 2014, 06:40:57 PM »
Hi,

 You need that proxy on all your scenes, OR make it not destroyable on level load.

Is that the case?

bye,

 Jean

I don't really understand what that means. Are you talking about having them on every game object that uses 2d, or just the PlayMaker Unity 2D prefab? Either way it is halting my project and it's really frustrating. I wish I knew how to use this tool better.

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
Re: Unity 2D and Physics 2D Support now available
« Reply #44 on: January 30, 2014, 07:57:56 PM »
The "PlayMaker Unity 2D" Prefab needs to exist exactly *once* in every scene.

The PlayMakerUnity2DProxy component needs to be added to every 2D gameobject that you want Playmaker to detect 2D collisions / triggers on.

Perhaps confusion might come from some of the wording as Jean has sometimes called the prefab component the Proxy (while in the package the Proxy is the component you must add to each gameobject).
« Last Edit: January 30, 2014, 08:00:45 PM by dasbin »