playMaker

Author Topic: Some ConfigurableJoint Actions  (Read 1849 times)

cwmanley

  • Full Member
  • ***
  • Posts: 107
Some ConfigurableJoint Actions
« on: September 20, 2016, 12:48:31 AM »
Hi,

SetConfigurableJointLimits
SetConfigurableJointDrives

On the Ecosystem or https://snipt.net/cwmanley/

//TODO

Thanks

Code: [Select]
// License: Attribution 4.0 International (CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Keywords: ConfigurableJoint, Joint

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Sets the Drives on a Configurable Joint Component")]
public class SetConfigurableJointDrives : FsmStateAction
{
[RequiredField]
[Tooltip("The Game Object with the ConfigurableJoint component")]
[CheckForComponent(typeof(ConfigurableJoint))]
public FsmOwnerDefault gameObject;

[Tooltip("How the joint's movement will behave along its local axis.")]
public Drives driveType;

[Tooltip("Strength of a rubber-band pull toward the defined direction. Only used if mode includes Position.")]
public FsmFloat positionSpring;

[Tooltip("Resistance strength against the Position Spring. Only used if mode includes Position.")]
public FsmFloat positionDamper ;

[Tooltip("Amount of force applied to push the object toward the defined direction.")]
public FsmFloat maximumForce;

public bool everyFrame;

public enum Drives{
DriveX,
DriveY,
DriveZ,
DriveAngluarX,
DriveAngluarYZ,
DriveSlerp
}

public override void Reset()
{
gameObject = null;
driveType = Drives.DriveX;
maximumForce = 3.402823e+38f;
positionDamper = 0f;
positionSpring = 0f;
everyFrame = false;

}

public override void OnEnter()
{
DoAction();

if (!everyFrame)
{Finish();
}
}

public override void OnUpdate(){
DoAction();
}

void DoAction(){

GameObject go = Fsm.GetOwnerDefaultTarget (gameObject);

if (go == null) {
return;
}

ConfigurableJoint cj = go.GetComponent<ConfigurableJoint> ();

if (cj == null) {
return;
}


JointDrive jd = new JointDrive ();

jd.maximumForce = maximumForce.Value;
jd.positionDamper = positionDamper.Value;
jd.positionSpring = positionSpring.Value;


//
switch (driveType)
{
case Drives.DriveX:
{
cj.xDrive = jd;
}
break;
case Drives.DriveAngluarX:
{
cj.angularXDrive = jd;
}
break;
case Drives.DriveAngluarYZ:
{
cj.angularYZDrive = jd;
}
break;
case Drives.DriveZ:
{
cj.zDrive = jd;
}
break;
case Drives.DriveY:
{
cj.yDrive = jd;
}
break;
case Drives.DriveSlerp:
{
cj.slerpDrive = jd;
}
break;
}
//

}
}
}


Code: [Select]
// License: Attribution 4.0 International (CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Keywords: ConfigurableJoint, Joint

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Sets the Drives on a Configurable Joint Component")]
public class SetConfigurableJointDrives : FsmStateAction
{
[RequiredField]
[Tooltip("The Game Object with the ConfigurableJoint component")]
[CheckForComponent(typeof(ConfigurableJoint))]
public FsmOwnerDefault gameObject;

[Tooltip("How the joint's movement will behave along its local axis.")]
public Drives driveType;

[Tooltip("Strength of a rubber-band pull toward the defined direction. Only used if mode includes Position.")]
public FsmFloat positionSpring;

[Tooltip("Resistance strength against the Position Spring. Only used if mode includes Position.")]
public FsmFloat positionDamper ;

[Tooltip("Amount of force applied to push the object toward the defined direction.")]
public FsmFloat maximumForce;

public bool everyFrame;

public enum Drives{
DriveX,
DriveY,
DriveZ,
DriveAngluarX,
DriveAngluarYZ,
DriveSlerp
}

public override void Reset()
{
gameObject = null;
driveType = Drives.DriveX;
maximumForce = 3.402823e+38f;
positionDamper = 0f;
positionSpring = 0f;
everyFrame = false;

}

public override void OnEnter()
{
DoAction();

if (!everyFrame)
{Finish();
}
}

public override void OnUpdate(){
DoAction();
}

void DoAction(){

GameObject go = Fsm.GetOwnerDefaultTarget (gameObject);

if (go == null) {
return;
}

ConfigurableJoint cj = go.GetComponent<ConfigurableJoint> ();

if (cj == null) {
return;
}


JointDrive jd = new JointDrive ();

jd.maximumForce = maximumForce.Value;
jd.positionDamper = positionDamper.Value;
jd.positionSpring = positionSpring.Value;


//
switch (driveType)
{
case Drives.DriveX:
{
cj.xDrive = jd;
}
break;
case Drives.DriveAngluarX:
{
cj.angularXDrive = jd;
}
break;
case Drives.DriveAngluarYZ:
{
cj.angularYZDrive = jd;
}
break;
case Drives.DriveZ:
{
cj.zDrive = jd;
}
break;
case Drives.DriveY:
{
cj.yDrive = jd;
}
break;
case Drives.DriveSlerp:
{
cj.slerpDrive = jd;
}
break;
}
//

}
}
}
« Last Edit: February 15, 2017, 01:59:29 PM by cwmanley »