Search Unity

GenerateImpulse Velocity

Discussion in 'Cinemachine' started by darthbator, Jul 15, 2018.

  1. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    So I've started using the new impulse system and it's been super easy to use for getting little generic screen shakes going on for events in my game. However I'm a little stymied when it comes to using it for something a little more controlled.

    I'm trying to generate an impulse that will basically PingPong from 0 up to the fed in velocity and then back down to 0. Basically an extremely predictable "kick" in a camera direction that I could use for wall collisions of the kickback of a gun. It's a system that I had before that I'd ideally like to replace by something more native to cinemachine.

    I've generated my own Raw Signals trying a few different settings but can never seem to get the camera to simply track the velocity that's passed into the system. I always seem to cause the camera to move in strangely unpredictable directions (probably the result of the curve data combined with the velocity data I'm passing into the Impulse Source). Am I going about this in the correct way?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Have a look at the Impulse scene that's shipped with the Cinemachine Example Asset package. It does exactly that with the signal shape on the Magic Box object.

    It defines a simple constant signal that's 0 in X and Z, and 1 in Y. Then, the resulting motion in Y will be exactly the envelope shape, which will be rotated in the direction of the velocity, and scaled with the speed and gain. Exactly what you're looking for, I think.
     
  3. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    That is exactly what I'm looking for! However I'm for some reason not seeing the behavior demonstrated in that scene.

    So I'm using an ortho camera and I'm looking to get it to bounce around in said manner in X/Y space. So I generate a custom constant signal with a flat 1 X and Y curve and a flat 0 Z curve.

    I then call the impulse as follows for testing

    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.N)) {
    2.             impulse.GenerateImpulse(new Vector3(0, 5f, 0));
    I expect to see the camera bounce upwards in Y world space over the 1s described in the time envelope. However what actually happens is the camera bounces up and left (almost looking like V2(-5, 5) or something?). Is this a bug that somehow occurs due to the ortho camera? That doesn't make sense to me but I'm at a loss for what else I might be doing incorrectly.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You're getting the diagonal because you put 1 in X and Y. Put 1 in Y, and 0 in X and Z. That gives you a 1D movement in Y, which will then be rotated in the XY plane if that's what your velocity is doing.
     
    Last edited: Jul 16, 2018
  5. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Helps when I just follow directions and don't get crazy trying to be "smart". Thanks so much for your continuing help here on this forum! The level of support you give on here is among the best features of this asset.
     
    Gregoryl likes this.