FANDOM


Note: This AC action allows you to set and and adjusts the FBBIK body effector.

I've been working to create custom actions that allow for direct access to the FBBIK component through Adventure Creator. So far I've developed one for the Body and another for Limbs. I haven't tested them exhaustively or anything but they appear to actually work.
To use it replace the text in a .cs file named FinalIK_BodyEffector with this text, or create a new blank text file, then paste the text and rename the file FinalIK_BodyEffector.cs. Then drop the file into the folder named actions inside the Adventure creator folder. Then, just use the action in an action list.

Script:

using UnityEngine;
using System.Collections;
using RootMotion.FinalIK;

#if UNITY_EDITOR
using UnityEditor;
#endif
 
 namespace AC
 {
 	[System.Serializable]
 	public class FinalIK_BodyEffector : Action
 	{
 		public bool isPlayer;
         public FullBodyBipedIK targetchar;

        //Body
         //The target Transform (optional, you can use just the position instead)
        public GameObject target;

        //Set the effector position to a point in world space. This has no effect if the effector's positionWeight is 0
        public Vector3 position;

        //Weight of the effector position
        public float positionWeight;

        //If false, child nodes will be ignored
        public bool useThighs;

        //Chain
         //The bend resistance of the spine
        public float spineStiffness;

        //Weight of hand effectors pulling the body vertically
        public float pullBodyVertical;

        //Weight of hand effectors pulling the body horizontally             
        public float pullBodyHorizontal;

        //Mapping
        //Spine mapping iteration count
        public int spineMappingIterations;

        //Weight of twisting the spine bones to the chest triangle
        public float spineTwistWeight;

        //The weight of maintaining the bone's animated rotation in world space
        public float maintainHeadRotation;


        public FinalIK_BodyEffector()
		{
			this.isDisplayed = true;
			category = ActionCategory.Custom;
			title = "Final IK - Body Effector";
			description = "Sets and adjusts the FBBIK body effector";
			isPlayer = true;
           
         }
 		
 		override public float Run()
 		{
 			if (isPlayer)
 			{
 				targetchar = KickStarter.player.GetComponent<FullBodyBipedIK>();
 				
 				if (targetchar == null)
 				{
 					Debug.LogWarning("FinalIK_BodyEffector: No FBBIK component found on Player.");
 					return 0f;
 				}
 			}
 
             positionWeight = Mathf.Clamp(positionWeight, 0f, 1f);
            spineMappingIterations = Mathf.Clamp(spineMappingIterations, 1, int.MaxValue);
            spineStiffness = Mathf.Clamp(spineStiffness, 0f, 1f);
            pullBodyVertical = Mathf.Clamp(pullBodyVertical, 0f, 1f);
            pullBodyHorizontal = Mathf.Clamp(pullBodyHorizontal, 0f, 1f);
            maintainHeadRotation = Mathf.Clamp(maintainHeadRotation, 0f, 1f);
            spineTwistWeight = Mathf.Clamp(spineTwistWeight, 0f, 1f);

            targetchar.solver.bodyEffector.target = target == null ? null : target.transform;
            targetchar.solver.bodyEffector.position = position;
            targetchar.solver.bodyEffector.positionWeight = positionWeight;
            targetchar.solver.bodyEffector.effectChildNodes = useThighs;
            targetchar.solver.spineMapping.iterations = spineMappingIterations;
            targetchar.solver.spineStiffness = spineStiffness;
            targetchar.solver.pullBodyVertical = pullBodyVertical;
            targetchar.solver.pullBodyHorizontal = pullBodyHorizontal;
            targetchar.solver.spineMapping.twistWeight = spineTwistWeight;
            return 1f;
            
         }
 
 		override public void Skip(){       
                         
 		}
         		
 		#if UNITY_EDITOR
 		override public void ShowGUI()
 		{
 			isPlayer = EditorGUILayout.Toggle("Is player?", isPlayer);
 			
 			if (!isPlayer)
 			{
 				targetchar = (FullBodyBipedIK)EditorGUILayout.ObjectField("Character:", targetchar, typeof(FullBodyBipedIK), true);
 			}
 	
 		
 			target = (GameObject)EditorGUILayout.ObjectField("Body Effector Target:", target, typeof(GameObject), true);
             position = (Vector3)EditorGUILayout.Vector3Field("Position:", position);
            positionWeight = EditorGUILayout.Slider("Position Weight:", positionWeight, 0f, 1f);
            useThighs = EditorGUILayout.Toggle("Use Thights?", useThighs);
            spineMappingIterations = EditorGUILayout.IntSlider("Spine Iterations:", spineMappingIterations, 0, 3);
            spineStiffness = EditorGUILayout.Slider("Spine Stiffness:", spineStiffness, 0f, 1f);
            pullBodyVertical = EditorGUILayout.Slider("Pull Body Vertical:", pullBodyVertical, 0f, 1f);
            pullBodyHorizontal = EditorGUILayout.Slider("Pull Body Horizontal:", pullBodyHorizontal, 0f, 1f);
            spineTwistWeight = EditorGUILayout.Slider("Spine Twist Weight:", spineTwistWeight, 0f, 1f);



            AfterRunningOption();
		}
		#endif
	}
}

[Script provided by user Larsos]

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.