Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    89
    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:
    2,056
    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:
    89
    Thanks as always for the fast reply, I appreciate it.
     
  4. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    89
    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:
    89
    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:
    2,056
    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.
  7. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    89
    Thanks, I've managed to use SmoothDamp and I'm setting max speed. Now it looks much better.

    One more thing, is it possible to make the "speed up" and "speed down" of SmoothDamp faster? It takes a good ~2 seconds to go from the max speed to 0 speed. That's too long. Is it possible to make this faster?

    I've tried changing velocity directly but it gets real messy, I thought I should just ask you for advice.

    Thanks. :)
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,056
    upload_2019-1-23_9-58-22.png

    Have you tried using smaller values for smoothTime?
     
  9. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    89
    Oh, gosh, thank you! I tried that at first without using maxSpeed; back then it didn't work of course. Combined WITH maxSpeed it does exactly what I need. Thank you so much. =)