Search Unity

Using mouse drag to move created points on a game object

Discussion in 'Scripting' started by Need_for_sleep117, Nov 25, 2014.

  1. Need_for_sleep117

    Need_for_sleep117

    Joined:
    Nov 25, 2014
    Posts:
    2
    It involves GameObjects to be able to bend to a certain degree through the player's "click and drag" with the mouse. The object I think will require points with a degree limitation. For each object, there will be multiple points (or joints) in the object that the player can use to manipulate and form a letter. For example the object will start off as sort of like an "I", which will have multiple points to it. The player will click and drag the top-most point and circle it around to the point 3/4 down the line to create "P". I have searched for tutorials on both Unity website and youtube but can't seem to find one that specifies on this specific issue. Plus I'm not sure if I can make a single capsule and drastically increase the "y axis" to make it an "I" then apply the multiple points on the one object. The letter, after the clicking and dragging the point will have to be "smooth" so the edges are not jagged.
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    You need to formulate your question better and include your code. Noone can understand what you want and thus cannot help you.
     
  3. fox4snce

    fox4snce

    Joined:
    Jan 25, 2014
    Posts:
    74
    Need_For_Sleep: I think you might have a lot of difficulty with this. What I gather from your post is you're basically trying to draw geometry using user input. I believe it's possible but only to a limited degree and only using shaders. I'm not an expert but I have yet to see any other possible way to do what you want.

    Often, there is the option to "fake it" which is unfortunately common.

    Here's what I would recommend. Create a series of 3d models for each of these transformations that you want to occur.

    Create colliders for the points you want a player to click on.

    When they move these points in the correct direction, display the series of 3d models according to what direction or point they have reached.

    If you set up a series of if statements (or some better method) you can allow a user to "draw" multiple shapes even though they aren't really drawing anything.

    It fakes what you want to do.. without trying to do something that might be impossible. Again, I am not an expert. Maybe someone else will shed some light.

    Good luck!
     
  4. Need_for_sleep117

    Need_for_sleep117

    Joined:
    Nov 25, 2014
    Posts:
    2
    Thing is, I don't know the code to use for this situation, all of it is practically user controlled. I believe I need a void for the OnMouseDown to initiate the "grab function" so the cursor holds on to the point and a OnMouseDrag to make the point follow the cursor to the designated area. but this will not be a straight line. As the line being moved reaches it's limited angle, it then causes the line to stop rotating and start transforming as the second line starts to rotate to it's limit and the next line starts rotating. All of it is really going to be just one prefab. But the code required is whats really being the pain here.
     
  5. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    I think you need transform.position and Camera.main.ScreenPointToRay to do what you want. Get the screen coordinates and set the transforms position to those. You can get the angle between two points with Vector3.Angle or use Mathf.Atan2.