Search Unity

How to get a ball to go through a pipe?

Discussion in '2D' started by jbassking, Jun 29, 2015.

  1. jbassking

    jbassking

    Joined:
    Feb 27, 2014
    Posts:
    118
    I want to make a ball fall into a pipe and come out the other end. I thought I could use an edge collider to make it look like the ball fell into the pipe and then use an edge collider with many points to direct the ball to the other end of the tube.
    One problem I'm having it I can't seem to get the edge collider to create new vertex by following these instructions:
    "If you shift-drag while the mouse is over an edge then a new vertex will be created at the mouse location. You can remove a vertex by holding down the ctrl/cmd key while clicking on it."

    Does anyone know of any good examples of how to do this?

    BTW - this is a 2D game.

    Thanks.
     
    Last edited: Jun 29, 2015
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    You could use AreaEffector2d to allow Objects to control its movement :
     
    sluice likes this.
  3. Calvin_

    Calvin_

    Joined:
    Apr 21, 2014
    Posts:
    25
    You could make a simple pipe in something like Blender, and then make the ball fall through using physics.
     
  4. v2-Ton-Studios

    v2-Ton-Studios

    Joined:
    Jul 18, 2012
    Posts:
    238
    How realistic do you want to ball to feel? You could just move the ball through a set of points that you position by hand.
     
  5. Runalotski

    Runalotski

    Joined:
    Mar 4, 2014
    Posts:
    10
    Have you tried not shift clicking it.

    if you hover your mouse between two points along the line you should get a green square where you mouse is just click and drag and it will make that a new point.
     
  6. Runalotski

    Runalotski

    Joined:
    Mar 4, 2014
    Posts:
    10
    Or if that fails you can make it in script if you make a game object and attach two edgecolliders to it and then add this script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. //This is needed to use List<T>
    5. using System.Collections.Generic;
    6.  
    7. public class Colliders2D : MonoBehaviour {
    8.  
    9.     //A List to hold points for A line
    10.     public List<Vector2> VertsTopOfPipe = new List<Vector2>();
    11.  
    12.     //A List to hold points for a second Line
    13.     public List<Vector2> VertsBottomOfPipe = new List<Vector2>();
    14.  
    15.     //An Array to hold the list of EdgeCollider2D on the game object
    16.     private EdgeCollider2D[] col;
    17.  
    18.     // Use this for initialization
    19.     void Awake() {
    20.  
    21.         //This will retuern all Components that are an edgecollider
    22.         col = GetComponents<EdgeCollider2D>();// note GetComponentS<> is plural
    23.  
    24.         //pick some points in 2d relative to game object
    25.         VertsTopOfPipe.Add( new Vector2(0, 1) );
    26.         VertsTopOfPipe.Add( new Vector2(1, 1) );
    27.         VertsTopOfPipe.Add( new Vector2(2, 1) );
    28.         VertsTopOfPipe.Add( new Vector2(3, 1) );
    29.         VertsTopOfPipe.Add( new Vector2(4, 1) );
    30.  
    31.  
    32.         //And again for the second list
    33.         VertsBottomOfPipe.Add( new Vector2(0, -1) );
    34.         VertsBottomOfPipe.Add( new Vector2(1, -1) );
    35.         VertsBottomOfPipe.Add( new Vector2(2, -1) );
    36.         VertsBottomOfPipe.Add( new Vector2(3, -1) );
    37.         VertsBottomOfPipe.Add( new Vector2(4, -1) );
    38.  
    39.     }
    40.  
    41.     void setPoints() {
    42.         //now col is our array of edgeCollider2D we can index each one from 0
    43.         col[0].points = VertsTopOfPipe.ToArray();
    44.  
    45.         col [1].points = VertsBottomOfPipe.ToArray ();
    46.     }
    47.  
    48.     //start function runs onces
    49.     void Start () {
    50.         setPoints();  
    51.     }
    52. }
    it will make a straight pipe, you can ajust the length size and how many points it has in the verts arrays its can be long but it will work, also the point are relative to the game object its attached to so if you get the shap you want you can the rotate it in the editor.

    I use this as the editing the edge collider in the editor seems to be completly random if it wokrs for me.
     
    Last edited: Jul 1, 2015
    LSalatino likes this.
  7. jbassking

    jbassking

    Joined:
    Feb 27, 2014
    Posts:
    118
    Hi everyone. Sorry for the late reply.
    It turned out I was clicking in the wrong spot. I watched a video on the edge collider and that took care of that.

    Thanks for all the suggestions though.