playMaker

Author Topic: Set Rigidbody2D BodyType & Simulated  (Read 1205 times)

Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Set Rigidbody2D BodyType & Simulated
« on: September 25, 2018, 01:15:35 PM »
SetRigidBodyType2D
The action allows you to change the body type and simulated parameters in a Rigidbody 2D (I was surprised that no acion exists, or I overlooked it).

Purpose
I needed the action because I have physics objects in the scene that are tempoarily bound to the character, for which these parameters need to be changed temporarily. But it's probably an esoteric need.

Small Caveat
In a perfect action, the body type drop down's default would be "don't change". However, it's populated by Unity enums and I don't know how to add a nice extra option in there. However, that's cosmetics.

My simple workaround is a bool that asks if you want to leave body type alone, and only change the simulated property (which was what I needed in the end). Perhaps a more elegant way would be to split the action into two, for each separate setting.

I also read in documentation that these changes are best in FixedUpdate. But when I plug them there, they show no effect. It's now a standard OnEnter affair, and works.

As Usual
Anyone can of course use this and modify it. Someone with access can also upload it to Ecosystem, too (though beware, I am not a coder, please doublecheck). ;)
« Last Edit: September 25, 2018, 05:59:51 PM by Thore »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: Set Rigidbody2D BodyType & Simulated
« Reply #1 on: September 26, 2018, 12:41:18 AM »
Hi.
I have updated the action so it works the way you wanted it to work :)

As you are not updating, but only set this once.

fixedupdate is not needed.

and also added to the Ecosystem

Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Set Rigidbody2D BodyType & Simulated
« Reply #2 on: September 26, 2018, 05:08:11 AM »
Thanks a lot, and especially for the "cosmetic" fix. ;)


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: Set Rigidbody2D BodyType & Simulated
« Reply #3 on: September 26, 2018, 05:33:34 AM »
Hi,
NO problem, did you check out the script and understand what i did?

Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Set Rigidbody2D BodyType & Simulated
« Reply #4 on: September 26, 2018, 06:42:37 AM »
I did, of course, and it also works in my setting. I was on a similar track, at first, but had a syntax bug in there somewhere (hence why I'm using Playmaker in the first place) and then gave up on that idea, thinking it's probably some convoluted trick I didn't know. Didn't keep the broken version, alas, cannot check what exactly I did wrong.



djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: Set Rigidbody2D BodyType & Simulated
« Reply #5 on: September 26, 2018, 07:17:53 AM »
Hi.
Actually i had to google myself to see how i could use an enum with an enum :)

There are 2 ways, one by using the index (which i am doing in the action and that's why 'do nothing'  is set last)
The other way is more complex by using the name.

Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Set Rigidbody2D BodyType & Simulated
« Reply #6 on: September 05, 2019, 04:40:22 AM »
Hi djaydino,

The action works nicely, however I found some improvements:

Code: [Select]
[ActionCategory(ActionCategory.Physics2D)] needs the 2D to be listed correctly.

Code: [Select]
ComponentAction<Rigidbody2D> also should have the 2D attached, too. Component action is potentially superfluous if it worked before.
 
Code: [Select]
simulated = true; rigidbody2d are simulated (true) by default.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: Set Rigidbody2D BodyType & Simulated
« Reply #7 on: September 11, 2019, 10:17:18 PM »
Hi,

 Cool, Kurt can you put that on the ecosystem? thanks.

Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: Set Rigidbody2D BodyType & Simulated
« Reply #8 on: September 26, 2019, 02:04:55 AM »
Hi.
It is already on the Ecosystem, but have updated the Category.

Code: [Select]
ComponentAction<Rigidbody2D>
The line above is already good on the Ecosystem version.

Due to that it is already on the Ecosystem i think it is best to leave the default as is.