Search Unity

Screen/Cursor-Alligned Object Interaction/Controls

Discussion in 'Scripting' started by Studio_Akiba, Aug 19, 2018.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    So, I'm trying to replicate a similar effect to the levers, drawers and wheels in games like Myst, where the player can (within a declaired radius/area) move a lever (for example) around a pivot point with a min and max rotation by grabbing it (using left-click, or a trigger) and moving the cursor/camera in the direction the lever can move.

    My main question about achieving these is: how does one translate screen-centre/cursor position to a movement-restricted object in Unity?

    Here's a video of the effect I'm after (although I may have the cursor togglable locked to centre screen).

    http://kylebriggs.co.uk/wp-content/uploads/2018/08/Myst-IV-Revelation-8_19_2018-5_18_06-PM.mp4
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    451
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    I would approach this from the opposite direction -- translate your world space object motion into screen space. Define a world space "motion path" that the player's "hand" needs to take. When the player first interacts with the object, translate that path into screen space and calculate the motion there in 2D. Should simplify the problem considerably.