Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to make to target with constant speed?

Discussion in 'Cinemachine' started by roseportalgames, Nov 29, 2018.

  1. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    55
    Hi guys,

    In my 2D game I have a camera who is Follow on a gameObject, I call it "camera target". I move this target around so I can move the camera.

    However, if I move the target the camera goes REALLY FAST to the target at first then slows down (so, Ease Out only). I increased damping which makes it slow, but it still goes too fast right from the beginning.

    How can I make it move more like Ease In Ease Out instead of just Ease Out?

    Thanks,
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,823
    You can make a custom version of the FramingTransposer with your own damping implementation. Copy CinemachineFramingTransposer.cs, rename it, and then your copy will automagically appear in the Body dropdown of the vcam.

    Instead of calling "Damper.Damp()" use your own damping implementation that does the easeIn/easeOut.
     
    roseportalgames likes this.
  3. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    55
    Thanks as always for the fast reply, I appreciate it.
     
  4. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    55
    Hm, I'm getting some weird stuff when I want to copy CinemachineFramingTransposer from the Assembly Browser.

    e.g.

    internal Rect HardGuideRect {
    get {
    //IL_003d: Unknown result type (might be due to invalid IL)
    //IL_006a: Unknown result type (might be due to invalid IL)
    //IL_006f: Unknown result type (might be due to invalid IL)
    //IL_0079: Unknown result type (might be due to invalid IL)
    //IL_007a: Unknown result type (might be due to invalid IL)
    //IL_0080: Unknown result type (might be due to invalid IL)
    Rect result = default(Rect);
    result..ctor (this.m_ScreenX - this.m_SoftZoneWidth / 2f, this.m_ScreenY - this.m_SoftZoneHeight / 2f, this.m_SoftZoneWidth, this.m_SoftZoneHeight);
    result.set_position (result.get_position () + new Vector2 (this.m_BiasX * (this.m_SoftZoneWidth - this.m_DeadZoneWidth), this.m_BiasY * (this.m_SoftZoneHeight - this.m_DeadZoneHeight)));
    return result;
    }


    I'm not sure where I can find the proper .cs file

    I'm also thinking I might need CinemachineTransposer and not CinemachineFramingTransposer because it's a 2D game?
     
    Last edited: Nov 30, 2018
  5. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    55
    Could you maybe give a start on how I should use my own function to create an Ease In/Ease Out or at least a more constant speed? The way Damper.Damp is recursively written makes it difficult for met to understand what is going on.

    Thank you. :)
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,823
    You could use either the transposer or the framing transposer, whichever one better suits your needs. I can't recommend one over the other because I don't really know what you're trying to do. I suggest that you get it working the way you like - minus the damping mod - with the default CM classes, then add the custom damping at the end. That way you're free to experiment.

    The best way to find the cs file is to edit the script from Unity:

    upload_2018-12-3_9-42-52.png

    For the damping, have a look at https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
    Maybe that will give what you're after.
    You'll need to keep a current velocity variable, and maintain it appropriately.
     
    roseportalgames likes this.