Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to change LimbSolver2D property Effector in script

Discussion in '2D' started by Smilecookie, May 2, 2022.

  1. Smilecookie

    Smilecookie

    Joined:
    Mar 22, 2014
    Posts:
    9
    In an animation created using LimbSolver2D, when a character with the same character is replaced during runtime, I want to use a script to change the associated effector to the bone of the new character. But I can't find the effector anywhere in the script.
    Is there a way?

    Thanks.
     
  2. DavidTeo

    DavidTeo

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    69
  3. StaticWave

    StaticWave

    Joined:
    Aug 21, 2016
    Posts:
    17
    I also noticed there is no way to set the effector transform programaticlly, without using the editor. If im missing this functionality let me know, but it would be nice if or something like it was added to LimbSolver2D.

    https://github.com/needle-mirror/com.unity.2d.animation/blob/master/IK/Runtime/LimbSolver2D.cs


    Code (CSharp):
    1.  public virtual void setEffector(Transform effectorTarget)
    2.         {
    3.             if (m_Chain != null)
    4.             {
    5.                 m_Chain.effector = effectorTarget;
    6.             }
    7.         }
    8.  
    9.         public virtual void createTarget()
    10.         {
    11.             IKChain2D chain = GetChain(GetChainCount());
    12.             if (chain != null && chain.target == null && chain.effector != null)
    13.             {
    14.                 chain.target = new GameObject(name + "_Target").transform;
    15.                 chain.target.SetParent(transform);
    16.                 chain.target.position = chain.effector.position;
    17.                 chain.target.rotation = chain.effector.rotation;
    18.  
    19.             }
    20.         }
     
    Last edited: Apr 18, 2023
    EvOne likes this.
  4. zagrizzl

    zagrizzl

    Joined:
    Jul 17, 2019
    Posts:
    4