How to make to target with constant speed?

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,

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.

1 Like

Thanks as always for the fast reply, I appreciate it.

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?

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. :slight_smile:

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:

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

For the damping, have a look at Unity - Scripting API: Vector3.SmoothDamp
Maybe that will give what you’re after.
You’ll need to keep a current velocity variable, and maintain it appropriately.

1 Like

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. :slight_smile:

Have you tried using smaller values for smoothTime?

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. =)