Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this community.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
 
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
[About macOS Ventura 13.0] (12/20/2022)
The currently released Live2D Cubism SDK is not guaranteed to work with macOS Ventura.
Please refrain from upgrading the macOS as they may not work properly.
The Cubism Editor license file may be lost after the macOS upgrade.
Please make sure to deactivate the Cubism Editor license before upgrading the macOS.
For more details
[NOTICE]
About the support for Mac models
Cubism Editor is not supported with Apple M1 processors.
Please refer to System Requirements for details.
We will not respond to any related inquiries with this message.

How do I loop a motion while touch swiping?

edited February 2016 in Help
I'm in process of understanding the framework right now. I've examined the SampleApp1 code and I can see that if I swipe on the head, it will only play the motion once. Same goes for the body.
How do I make a motion keep looping when I swipe on the head? When I swipe on the head or the body, it will loop same motion over and over until I released my touch and it will slowly fade to idle state.

It's kind of something like this (skip to 3:21) https://youtu.be/w5gQhcxTmuI?t=3m21s
While that it seems it only loops the face expression but I wonder if I can apply motion for the whole parts too.

Thank you :)

Tagged:

Comments

  • Hi, Ran_TH .

    Try to modify the code as follows .
    The modified point was put comments (Add Code) .

    SampleApp1/Assets/Scripts/sample
    [LAppModelProxy.cs]
    public class LAppModelProxy : MonoBehaviour
    {
        public String path="";
        public int sceneNo = 0;
    
        private LAppModel model;
        //---- Add Code start(set swip motion file) ----//
        public TextAsset swipingMtn;
        //---- Add Code end(set swip motion file) ----//
    
        private bool                isVisible = false ;
    	
    	void Awake()
        {
            if (path == "") return;
            model = new LAppModel(this);
    
            LAppLive2DManager.Instance.AddModel(this);
    
            var filename = FileManager.getFilename(path);
            var dir = FileManager.getDirName(path);
    
            Debug.Log("Load " + dir +"  filename:"+ filename);
    		model.LoadFromStreamingAssets(dir, filename);
    
        	// Add Code start(load swip motion file) ----//
            if(swipingMtn!=null)
                model.swipingMotion = Live2DMotion.loadMotion (swipingMtn.bytes);
        	// Add Code end(load swip motion file) ----//
        }
     ・
     ・
    
    set the swiping .mtn


    [LAppModel.cs]
     ・
     ・
        public void Init(String modelJson)
        {
     ・
     ・
            eyeBlink = new L2DEyeBlink();
    
            view.SetupView(
                live2DModel.getCanvasWidth(),
                live2DModel.getCanvasHeight());
    
            updating = false;
            initialized = true;
        }
    
        //---- Add Code start ----//
        bool isSwiping = false;
        public void setSwiping(bool b)
        {
            isSwiping = b;
        }
    
    	// All stop Motion
        public void stopAllMotions()
        {
            mainMotionManager.stopAllMotions ();
        }
    
        public AMotion swipingMotion;
        int motionno=-1;
        //---- Add Code end ----//
    
        public void Update()
        {
            if ( ! isInitialized() || isUpdating())
            {
                return;
            }
    
    
            view.Update(Input.acceleration);
            if (live2DModel == null)
            {
                if (LAppDefine.DEBUG_LOG) Debug.Log("Can not update there is no model data");
                return;
            }
    
            if (!Application.isPlaying)
            {
                live2DModel.update();
                return;
            }
    
            long timeMSec = UtSystem.getUserTimeMSec() - startTimeMSec;
            double timeSec = timeMSec / 1000.0;
            double t = timeSec * 2 * Math.PI;// 2πt
    
            if (mainMotionManager.isFinished())
            {
                StartRandomMotion(LAppDefine.MOTION_GROUP_IDLE, LAppDefine.PRIORITY_IDLE);
            }
    
            //---- Add Code start ----//
            if (mainMotionManager.isFinished (motionno) && isSwiping && swipingMotion!=null) 
            {
                Debug.Log ("----- SWIPING -----");
                motionno = mainMotionManager.startMotion (swipingMotion);
            }
            //---- Add Code end ----//
    
            live2DModel.loadParam();
            bool update = mainMotionManager.updateParam(live2DModel);
     ・
     ・
    
    [MyGameController.cs]
     ・
     ・
    	void Update () {
            if (Input.GetMouseButtonDown(0))
            {
                lastX = Input.mousePosition.x;
                lastY = Input.mousePosition.y;
                LAppLive2DManager.Instance.TouchesBegan(Input.mousePosition);
            }
            else if (Input.GetMouseButton(0))
            {
                if (lastX == Input.mousePosition.x && lastY == Input.mousePosition.y)
                {
                    return;
                }
                lastX = Input.mousePosition.x;
                lastY = Input.mousePosition.y;
                LAppLive2DManager.Instance.TouchesMoved(Input.mousePosition);
                //---- Add Code start(When no swipping) ----//
                GameObject.Find ("Live2D_Canvas_Haru").GetComponent<LAppModelProxy> ().GetModel ().setSwiping (true);
                //---- Add Code end(When no swipping) ----//
            }
            else if (Input.GetMouseButtonUp(0))
            {
                lastX = -1;
                lastY = -1;
                LAppLive2DManager.Instance.TouchesEnded(Input.mousePosition);
                //---- Add Code start(When no swipping) ----//
                GameObject.Find ("Live2D_Canvas_Haru").GetComponent<LAppModelProxy> ().GetModel ().setSwiping (false);
                GameObject.Find ("Live2D_Canvas_Haru").GetComponent<LAppModelProxy> ().GetModel ().stopAllMotions ();
                //---- Add Code end(When no swipping) ----//
            }
    
    The result will be this way .
  • edited December 2015
    You're truly a hero, naotaro. Thank you so much :D
    Now I've noticed, it does loop the motion, but at the end of motion, it will jump back to first frame. Can I make the loop returning to specific frame instead of first frame?



    I'd like to make my model keep in blushing state with eyes shut until I released my touch.

    Or should I used Expressions for this? I'm thinking like... when the motion ends, I switched to display the expression mimicking last frame of the motion.
  • Thanks! I'm aiming to Live2D hero o:)

    However , I don't know how to loop returning to specific frame .

    It is you're right .
    If your model keep in blushing state with eyes shut,
    I think that it is good to use Expressions motion also together .

    There is a simple Expressions use source in the past of thread .
    Please be here in reference .


    How do I change the model's expressions in Unity during gameplay?

Sign In or Register to comment.