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

Camera Pan / Movement with fixed mouse position

Discussion in 'Scripting' started by varigeri92, Jun 15, 2018.

  1. varigeri92

    varigeri92

    Joined:
    Jun 15, 2018
    Posts:
    3
    Hi, I have to Reproduce the exact Controls of the Google Maps, I got it fine until this point.
    If I just move the camera if is pointing straight down to the terrain, the mouse cursor stays there where I clicked, moving nice and smooth, but if I switch the view angle...
    mooving to the sides are just fine but if I try to move forward it draws a strange curve while moving, the point where I clicked is the exact the same after the movement. so the question is how can i get rid of this funky curve shaped movement?
    I can't upload the code but my steps:
    1.) Shoot a ray from the camera at the mouse position.
    2.) Save the position at the beginning of the drag.
    3.) Calculate the direction, and distance how the user moved the mouse since the last frame.
    4.) Lerp the camera's Parent to this point.

    As i said The movement is fine if the camera pointing straight down.
    if switch the camera angle (Rotating the camera parent on the x, so i can orbit around it),
    The movement still fine Left and Right the mouse cursor stay still above the object I was clicked on, no funky curves, no Mather wat angle the camera is looking, on the x or y,

    But if I want to go straight forward, the camera is going crazy, I got a strange curved or "S" shape movement, only in this case. I have no idea why...

    PS.:
    The hierarchy looks like:
    Camera rig Parent <- pos: 0,0,0 rot: 0,151.4,0 scale: 1,1,1 (the camera has to look in this direction)
    Camera_Rig <-this is what Im rotating and mooving around the scene the camera looks always this object, its position is always 0 at the y,
    Main Camera <- only moving on the local y while zooming,

    all the movements, and rotations, are on the local axes.

    Thx a lot for the help!

    PPS. : sorry my English is Bad :)

    PPPS.: if you don't understand me just open google maps and try the 3D View... if I want to move the camera forward or back... its not like there...