playMaker

Author Topic: Help modifying Joint action [SOLVED]  (Read 1319 times)

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Help modifying Joint action [SOLVED]
« on: March 19, 2012, 01:54:41 PM »
I'm trying to modify the SetJointConnectedBody action that Alex put up for me a few days ago.  
It turned out to support only Hinge Joints, but I would love to use it with a Spring Joint setup.  I tried making the modifications myself, but was unsuccessful.  Here's what I've got:

Basing it on the original script - -
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Connect a joint to a game object.")]
public class SetJointConnectedBody : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(HingeJoint))]
[Tooltip("The joint to connect. Requires a HingeJoint component.")]
public FsmOwnerDefault joint;

[CheckForComponent(typeof (Rigidbody))]
[Tooltip("The game object to connect to the Joint. Set to none to connect the Joint to the world.")]
public FsmGameObject rigidBody;

public override void Reset()
{
joint = null;
rigidBody = null;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(joint);
if (go != null)
{
go.hingeJoint.connectedBody = rigidBody.Value == null ? null : rigidBody.Value.rigidbody;
}
Finish();
}
}
}

I tried switching things out for the springJoint component using the same syntax (something that has worked for me before when editing Actions from other authors).

To This - -
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Connect a joint to a game object.")]
public class SetJointConnectedBody : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(SpringJoint))]
[Tooltip("The joint to connect. Requires a SpringJoint component.")]
public FsmOwnerDefault joint;

[CheckForComponent(typeof (Rigidbody))]
[Tooltip("The game object to connect to the Joint. Set to none to connect the Joint to the world.")]
public FsmGameObject rigidBody;

public override void Reset()
{
joint = null;
rigidBody = null;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(joint);
if (go != null)
{
go.springJoint.connectedBody = rigidBody.Value == null ? null : rigidBody.Value.rigidbody;
}

Finish();
}
}
}

I'm sure those of you who are veteran scripters/coders can immediately point out what I've done wrong, as I'm sure it's elementary.  I would really appreciate someone helping me with this.

Many thanks in advance!

« Last Edit: March 21, 2012, 01:17:20 PM by Alex Chouls »

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Re: Help modifying Joint action
« Reply #1 on: March 20, 2012, 03:49:41 PM »
*bump*

This can't be difficult, right?


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3616
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Help modifying Joint action
« Reply #2 on: March 20, 2012, 05:15:10 PM »
I'm going to modify the original action to work on any Spring. Will post in a bit...

However it also occurs to me that you can use Set Property for this. Have you tried that?

EDIT: I modified SetJointBody to work with any Joint type:
http://hutonggames.com/playmakerforum/index.php?topic=1227.0
« Last Edit: March 20, 2012, 05:32:01 PM by Alex Chouls »