Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Move objects along x and z axis only?

Discussion in 'Physics' started by Vexos, Jun 1, 2015.

  1. Vexos

    Vexos

    Joined:
    Jun 1, 2015
    Posts:
    19
    Hello! I've been stuck on this part for some days now and I cant seem to find any help or tutorials.
    What I'am looking for is a simple system which lets the player move objects from a camera along the X and Z axis ONLY. Besiege has the same system.

    Please help me! I'am trying to make a very fun game many wiill enjoy, I just need to get this working!
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    You could maybe set constraints to all the rigidbodies position in the Y axis. To do this you go to your rigidbody component, go to constraints, and check which axis you want to constrain.
     
  3. Vexos

    Vexos

    Joined:
    Jun 1, 2015
    Posts:
    19
    I know this but, I want the players to be able to move the objects while playing the game. Like if they were in editor mode.
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Ah, now I see. So you basically want to make a Transform tool for in game? The game Besiege seems to be shooting a raycast out of the mouse and if it hits a collider (which they all seem to be boxes) it will check which side it is hidding (most likely by getting the normals from the hitinfo) and then orientate the object the player selected and place it.
    If you just want some transform gizmo, maybe you would be able to use the GL class, or possible have sprits with colliders, or just even use a 3d model of a transform gizmo. So for example, you would have the X Y and Z each be their own box collider and parent them together. Then you would have it move to the selected objects position (you can get the selected objects position by doing a raycast from the mouse if the player clicks and get the collider the mouse is hitting, followed by the colliders transform position).
    Then you can either temporarily parent the selected object to the 3d transform gizmo, or have a way for the selected object to follow the 3d transform gizmo, and based on what box collider the player hits on the 3d gizmo, that is the position you slide the gizmo.

    Here is a Transform3DHandle prefab I made (A 3D runtime Gizmo / Transform Tool). It only handles translations. Just put it in your scene, press play, and click an object that has a collider on it. The 3d Gizmo should show up at the center of the object and you can slide it. You can also hold shift to select multiple or hold ctrl to deselect.
    This should be a nice starting point for you or anyone else.
     

    Attached Files: