Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Smoothing an up and down movement

Discussion in 'Scripting' started by BooBi, Jan 15, 2014.

  1. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    534
    Hi,

    I'm doing a first person view space shooter. The player's ship is on an orbit around the ennemies (only on the XZ plan (rotate around the Y axis), so on a circular orbit not a spherical) and it can pan up and down from his position on the orbit. For the rotation and the panning I've used the Fingergesture scripts (TBOrbit on an empty game object and TBPan on a camera which is child of the empty gameobject).
    $Orbit.jpg

    This is what I want to achieve:
    When you are at the highest point and you drag the camera down, I want a small rotation of the camera upwards, and the opposite when you move up from the bottom.
    $smooth movement-04.jpg

    A bit like what's happening with your pen inbetween your fingers when you move your hand up and down.
    $Rubberpenciltrick.png

    How can I achieve this ? Can someone send me to the right direction on how to do this please.

    Thanks a lot for your help
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    450
    I'm not totally sure if I even got what you are trying to achieve here. Here's my solution to what I understood =)
    Does the camera have a LookAt target? You could use that and give it an inverse, factored distance to it's original position based on the speed of the camera.
    Something like:
    Code (csharp):
    1.  
    2. LookAt = Vector3.zero -  myCamera.currentSpeed.y * 0,25f;
    3.  
    If you moved the camera down the LookAt would instead move up a little bit, giving you the impression of the camera looking up or down. When the speed of the camera is zero, also the offset of the LookAt would become zero.