PlayMaker Help & Tips > PlayMaker Help

Help modifying Joint action [SOLVED]

(1/1)

artician:
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: ---// (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();
}
}
}
--- End code ---

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: ---// (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();
}
}
}
--- End code ---

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!

artician:
*bump*

This can't be difficult, right?

Alex Chouls:
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

Navigation

[0] Message Index

Go to full version