Search Unity

Drag Shot Mover -- Get your physics objects moving!

Discussion in 'Made With Unity' started by LeadCarbonate, Apr 20, 2011.

  1. LeadCarbonate

    LeadCarbonate

    Joined:
    Mar 10, 2011
    Posts:
    18
    In the process of dipping my toes into Unity over the past few whiles I've come across a frequent need to just get a physics object moving in my scene for one reason or another. Most of the time its to test another element or make sure my physics materials are working the way I want them to. To make that nice and easy I wrote Drag-Shot Mover.

    It's a very simple script that allows you to click and drag to "snap" some force into an object. When you click the object a disc appears indicating the configurable orientation of the drag plane. As you drag away from the object the intended force grows and when you release ... pow. It's basically the slingshot from angry birds now that I think about it.

    Anyway, I'm fairly new to "serious" scripting so there's bound to be a few issues. I'll be happy to sort them out if folks let me know about them. The script is on the bulky side as its a bit "brute force" in the mesh construction department. Nevertheless, it works for me and I'm already using all over the place.

    Cheers -- LC

    DSMv01:
    Code (csharp):
    1.  
    2. /*
    3.     Drag-Shot Mover v01
    4.    
    5.     Desc: Allows force to be applied to the object by clicking that body
    6.     and dragging to designate a force vector with a maximum magnitude.
    7.    
    8.     TODO:
    9.         + set dead zone to a percentage
    10.         + add a "tension" option to the feel of the drag
    11.         + fancy, non-debug line
    12.         + add something to the disc that will make it clear how its tilted.
    13.        
    14.     Known Issues:
    15.        
    16.     Reminders / Caveats / Gotchas:
    17.         + OnMouseDown doesn't see the target object under another collider.  This is just
    18.           how Unity works.
    19.  
    20. */
    21.  
    22. @script RequireComponent(Rigidbody)
    23. @script RequireComponent(Collider)
    24.  
    25. var magBase : float = 2; // this is the base magnitude and the maximum length of the line drawn in the user interface
    26. var magMultiplier : float = 5; // multiply the line length by this to allow for higher force values to be represented by shorter lines
    27. var dragPlaneNormal : Vector3 = Vector3.up; // a vector describing the orientation of the drag plan relative to world-space but centered on the target
    28. var snapDirection : SnapDir = SnapDir.away; // force is applied either toward or away from the mouse on release
    29. var forceTypeToApply : ForceMode = ForceMode.VelocityChange;
    30.  
    31. var overrideVelocity : boolean = true; // cancel the existing velocity before applying the new force
    32. var pauseOnDrag : boolean = true; // causes the simulation to pause when the object is clicked and unpause when released
    33.  
    34. var noForceColor : Color = Color.yellow; // color of the visualization helpers at force 0
    35. var maxForceColor : Color = Color.red; // color of the visualization helpers at maximum force
    36.  
    37. enum SnapDir {toward, away}
    38.  
    39. private var forceVector : Vector3;
    40. private var magPercent : float = 0;
    41.  
    42. private var mouseDragging : boolean = false;
    43. private var mousePos3D : Vector3;
    44. private var dragDistance : float;
    45. private var dragPlane : Plane;
    46. private var mouseRay : Ray;
    47. private var dragZone : GameObject;
    48.  
    49. private var currentColor : Color = noForceColor;
    50.  
    51. private var shaderString : String = "Transparent/Diffuse";
    52. private var dzMat : Material;
    53.  
    54. function Start () {
    55.     dzMat = Material(Shader.Find(shaderString));
    56.    
    57.     // create the dragzone visual helper
    58.     dragZone = new GameObject("dragZone_" + gameObject.name);
    59.     dragZone.AddComponent(MeshFilter).mesh = MakeDiscMeshBrute(magBase/4);
    60.     //dragZone.GetComponent.MeshFilter.
    61.     dragZone.AddComponent(MeshRenderer);
    62.     dragZone.renderer.enabled = false;
    63.    
    64.     dragZone.name = "dragZone_" + gameObject.name;
    65.     dragZone.transform.localScale = Vector3(magBase*2, 0.025, magBase*2);
    66.     dragZone.renderer.material = dzMat;
    67.     dragZone.renderer.material.color = currentColor * Color(1,1,1,0.2);
    68.    
    69.     // create the dragplane
    70.     dragPlane = Plane(dragPlaneNormal, transform.position);
    71.    
    72.     // orient the drag plane
    73.     if (dragPlaneNormal != Vector3.zero) {
    74.         dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * Quaternion(1, 0, 0, 1);
    75.     }
    76.     else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    77.    
    78.     //update the position of the dragzone
    79.     dragZone.transform.position = transform.position;  
    80. }
    81.  
    82. function OnMouseDown () {
    83.     mouseDragging = true;
    84.    
    85.     if (pauseOnDrag) {
    86.         // pause the simulation
    87.         Time.timeScale = 0;
    88.     }
    89.    
    90.     // update the dragplane
    91.     dragPlane = Plane(dragPlaneNormal, transform.position);
    92.    
    93.     // orient the drag plane
    94.     if (dragPlaneNormal != Vector3.zero) {
    95.         dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * Quaternion(1, 0, 0, 1);
    96.     }
    97.     else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    98.    
    99.     //update the position of the dragzone
    100.     dragZone.transform.position = transform.position;
    101.    
    102.     dragZone.renderer.enabled = true;
    103. }
    104.  
    105. function OnMouseDrag () {
    106.     // update the plane if the target object has left it
    107.     if (dragPlane.GetDistanceToPoint(transform.position) != 0) {
    108.         // update dragplane by constructing a new one -- I should check this with a profiler
    109.         dragPlane = Plane(dragPlaneNormal, transform.position);
    110.     }
    111.    
    112.     // create a ray from the camera, through the mouse position in 3D space
    113.     mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    114.    
    115.     // if mouseRay intersects with dragPlane
    116.     var intersectDist : float;
    117.    
    118.     if (dragPlane.Raycast(mouseRay, intersectDist)) {
    119.         // update the world space point for the mouse position on the dragPlane
    120.         mousePos3D = mouseRay.GetPoint(intersectDist);
    121.        
    122.         // calculate the distance between the 3d mouse position and the object position
    123.         dragDistance = Mathf.Clamp((mousePos3D - transform.position).magnitude, 0, magBase);
    124.        
    125.         // calculate the force vector
    126.         if (dragDistance*magMultiplier < 1) dragDistance = 0; // this is to allow for a "no move" buffer close to the object
    127.         forceVector = mousePos3D - transform.position;
    128.         forceVector.Normalize();
    129.         forceVector *= dragDistance * magMultiplier;
    130.        
    131.         // update color the color
    132.         // calculate the percentage value of current force magnitude out of maximum
    133.         magPercent = (dragDistance * magMultiplier) / (magBase * magMultiplier);
    134.         // choose color based on how close magPercent is to either 0 or max
    135.         currentColor = noForceColor * (1-magPercent) + maxForceColor * magPercent;
    136.        
    137.         // dragzone color
    138.         dragZone.renderer.material.color = currentColor * Color(1,1,1,0.2);
    139.        
    140.         // draw the line
    141.         Debug.DrawRay(transform.position, forceVector / magMultiplier, currentColor);
    142.     }
    143.    
    144.     //update the position of the dragzone
    145.     dragZone.transform.position = transform.position;
    146. }
    147.  
    148. function OnMouseUp () {
    149.     mouseDragging = false;
    150.    
    151.     if (overrideVelocity) {
    152.         // cancel existing velocity
    153.         rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
    154.     }
    155.    
    156.     // add new force
    157.     var snapD : int = 1;
    158.     if (snapDirection == SnapDir.away) snapD = -1; // if snapdirection is "away" set the force to apply in the opposite direction
    159.     rigidbody.AddForce(snapD * forceVector, forceTypeToApply);
    160.    
    161.     // cleanup
    162.     dragZone.renderer.enabled = false;
    163.    
    164.     if (pauseOnDrag) {
    165.         // un-pause the simulation
    166.         Time.timeScale = 1;
    167.     }
    168.    
    169. }
    170.  
    171. function OnGUI () {
    172.     if (mouseDragging) {
    173.         var guiMouseCoord : Vector2 = GUIUtility.ScreenToGUIPoint(Input.mousePosition);
    174.         GUI.Box (Rect(guiMouseCoord.x-30, Screen.height-guiMouseCoord.y+15, 100, 20), "force: "+Mathf.Round((forceVector).magnitude));
    175.     }
    176. }
    177.  
    178. function MakeDiscMeshBrute (r : float) : Mesh {
    179.     var discMesh : Mesh;
    180.     var dmVerts : Vector3[] = new Vector3[18];
    181.     var dmNorms : Vector3[] = new Vector3[18];
    182.     var dmUVs : Vector2[] = new Vector2[18];
    183.     var dmTris : int[] = new int[48];
    184.     var i : int = 0;
    185.    
    186.     discMesh = new Mesh();
    187.    
    188.     dmVerts[0] = Vector3(0,0,0);
    189.     dmVerts[1] = Vector3(0,0,r);
    190.     dmVerts[2] = Vector3(1,0,1).normalized * r; // find the vector at the correct distance the hacky-hillbilly way!
    191.     dmVerts[3] = Vector3(r,0,0);
    192.     dmVerts[4] = Vector3(1,0,-1).normalized * r;
    193.     dmVerts[5] = Vector3(0,0,-r);
    194.     dmVerts[6] = Vector3(-1,0,-1).normalized * r;
    195.     dmVerts[7] = Vector3(-r,0,0);
    196.     dmVerts[8] = Vector3(-1,0,1).normalized * r;
    197.    
    198.     // set the other side to the same points
    199.     for (i = 0; i<dmVerts.length/2; i++) {
    200.         dmVerts[dmVerts.Length/2 + i] = dmVerts[i];
    201.     }
    202.    
    203.     for (i = 0; i<dmNorms.length; i++) {
    204.         if (i<dmNorms.length/2) dmNorms[i] = Vector3.up; // set side one to face up
    205.         else dmNorms[i] = -Vector3.up; // set side two to face down
    206.     }
    207.    
    208.     dmUVs[0] = Vector2(0,0);
    209.     dmUVs[1] = Vector2(0,r);
    210.     dmUVs[2] = Vector2(1,1).normalized * r;;
    211.     dmUVs[3] = Vector2(r,0);
    212.     dmUVs[4] = Vector2(1,-1).normalized * r;;
    213.     dmUVs[5] = Vector2(0,-r);
    214.     dmUVs[6] = Vector2(-1,-1).normalized * r;;
    215.     dmUVs[7] = Vector2(-r,0);
    216.     dmUVs[8] = Vector2(-1,1).normalized * r;;
    217.    
    218.     // set the other side to the same points
    219.     for (i = 0; i<dmUVs.length/2; i++) {
    220.         dmUVs[dmUVs.Length/2 + i] = dmUVs[i];
    221.     }
    222.    
    223.     dmTris[0] = 0;
    224.     dmTris[1] = 1;
    225.     dmTris[2] = 2;
    226.    
    227.     dmTris[3] = 0;
    228.     dmTris[4] = 2;
    229.     dmTris[5] = 3;
    230.    
    231.     dmTris[6] = 0;
    232.     dmTris[7] = 3;
    233.     dmTris[8] = 4;
    234.    
    235.     dmTris[9] = 0;
    236.     dmTris[10] = 4;
    237.     dmTris[11] = 5;
    238.    
    239.     dmTris[12] = 0;
    240.     dmTris[13] = 5;
    241.     dmTris[14] = 6;
    242.    
    243.     dmTris[15] = 0;
    244.     dmTris[16] = 6;
    245.     dmTris[17] = 7;
    246.    
    247.     dmTris[18] = 0;
    248.     dmTris[19] = 7;
    249.     dmTris[20] = 8;
    250.    
    251.     dmTris[21] = 0;
    252.     dmTris[22] = 8;
    253.     dmTris[23] = 1;
    254.    
    255.     // side two
    256.     dmTris[24] = 9;
    257.     dmTris[25] = 11;
    258.     dmTris[26] = 10;
    259.    
    260.     dmTris[27] = 9;
    261.     dmTris[28] = 12;
    262.     dmTris[29] = 11;
    263.    
    264.     dmTris[30] = 9;
    265.     dmTris[31] = 13;
    266.     dmTris[32] = 12;
    267.    
    268.     dmTris[33] = 9;
    269.     dmTris[34] = 14;
    270.     dmTris[35] = 13;
    271.    
    272.     dmTris[36] = 9;
    273.     dmTris[37] = 15;
    274.     dmTris[38] = 14;
    275.    
    276.     dmTris[39] = 9;
    277.     dmTris[40] = 16;
    278.     dmTris[41] = 15;
    279.    
    280.     dmTris[42] = 9;
    281.     dmTris[43] = 17;
    282.     dmTris[44] = 16;
    283.    
    284.     dmTris[45] = 9;
    285.     dmTris[46] = 10;
    286.     dmTris[47] = 17;
    287.    
    288.     discMesh.vertices = dmVerts;
    289.     discMesh.uv = dmUVs;
    290.     discMesh.normals = dmNorms;
    291.     discMesh.triangles = dmTris;
    292.    
    293.     return discMesh;
    294. }
    295.  
     
  2. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    An awesome share friend! Im totally playing around with my physics objects from now on! =)

    Thx!
     
  3. LeadCarbonate

    LeadCarbonate

    Joined:
    Mar 10, 2011
    Posts:
    18
    Glad it's working for you matey. Feel free to post bugs or feature requests here and I'll see what I can come up with.
     
  4. defjr

    defjr

    Joined:
    Apr 27, 2009
    Posts:
    436
    I love you.
     
  5. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    This is really useful, thanks
     
  6. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    cool, I need to use something like this later on so I will surely look at your code, although I'll have to do it in c#. Thanks for the share
     
  7. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    I tried to convert it to c# but get some errors.
    Maybe this can help someone as a translation starting point and we get together a working c# version out of this great script from LeadCarbonate :)


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DSMv01cs : MonoBehaviour {
    5. /*
    6.     Drag-Shot Mover v01
    7.    
    8.     Desc: Allows force to be applied to the object by clicking that body
    9.     and dragging to designate a force vector with a maximum magnitude.
    10.    
    11.     TODO:
    12.         + set dead zone to a percentage
    13.         + add a "tension" option to the feel of the drag
    14.         + fancy, non-debug line
    15.         + add something to the disc that will make it clear how its tilted.
    16.        
    17.     Known Issues:
    18.        
    19.     Reminders / Caveats / Gotchas:
    20.         + OnMouseDown doesn't see the target object under another collider.  This is just
    21.           how Unity works.
    22.  
    23. */
    24.  
    25. [RequireComponent (typeof (Rigidbody))]
    26. [RequireComponent (typeof (Collider))]
    27.  
    28.  
    29. public float magBase = 2; // this is the base magnitude and the maximum length of the line drawn in the user interface
    30. public float magMultiplier = 5; // multiply the line length by this to allow for higher force values to be represented by shorter lines
    31. public Vector3 dragPlaneNormal = Vector3.up; // a vector describing the orientation of the drag plan relative to world-space but centered on the target
    32. SnapDir snapDirection = SnapDir.away; // force is applied either toward or away from the mouse on release
    33. public ForceMode forceTypeToApply = ForceMode.VelocityChange;
    34.  
    35. public bool  overrideVelocity = true; // cancel the existing velocity before applying the new force
    36. public bool  pauseOnDrag = true; // causes the simulation to pause when the object is clicked and unpause when released
    37.  
    38. public Color noForceColor = Color.yellow; // jscript  "var noForceColor : Color = Color.yellow;"      // color of the visualization helpers at force 0
    39.  
    40.  
    41. public Color maxForceColor = Color.red; // color of the visualization helpers at maximum force
    42.  
    43. public enum SnapDir {toward, away}
    44.  
    45.  
    46.  
    47.  
    48. private Vector3 forceVector;
    49. private float magPercent = 0;
    50.  
    51. private bool  mouseDragging = false;
    52. private Vector3 mousePos3D;
    53. private float dragDistance;
    54. private Plane dragPlane;
    55. private Ray mouseRay;
    56. private GameObject dragZone;
    57.  
    58.  
    59.  
    60. private Color currentColor = noForceColor;  // jscript   "private var currentColor : Color = noForceColor;"
    61.  
    62.  
    63. private string shaderString = "Transparent/Diffuse";
    64. private Material dzMat;
    65.  
    66. void Start (){
    67.     dzMat = Material(Shader.Find(shaderString));
    68.    
    69.     // create the dragzone visual helper
    70.     dragZone = new GameObject("dragZone_" + gameObject.name);
    71.     dragZone.AddComponent<MeshFilter>().mesh = MakeDiscMeshBrute(magBase/4);
    72.     //dragZone.GetComponent.MeshFilter.
    73.     dragZone.AddComponent<MeshRenderer>();
    74.     dragZone.renderer.enabled = false;
    75.    
    76.     dragZone.name = "dragZone_" + gameObject.name;
    77.     dragZone.transform.localScale = Vector3(magBase*2, 0.025f, magBase*2);
    78.     dragZone.renderer.material = dzMat;
    79.     dragZone.renderer.material.color = currentColor * Color(1,1,1,0.2f);
    80.    
    81.     // create the dragplane
    82.     dragPlane = Plane(dragPlaneNormal, transform.position);
    83.    
    84.     // orient the drag plane
    85.     if (dragPlaneNormal != Vector3.zero) {
    86.         dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * Quaternion(1, 0, 0, 1);
    87.     }
    88.     else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    89.    
    90.     //update the position of the dragzone
    91.     dragZone.transform.position = transform.position;  
    92. }
    93.  
    94. void OnMouseDown (){
    95.     mouseDragging = true;
    96.    
    97.     if (pauseOnDrag) {
    98.         // pause the simulation
    99.         Time.timeScale = 0;
    100.     }
    101.    
    102.     // update the dragplane
    103.     dragPlane = Plane(dragPlaneNormal, transform.position);
    104.    
    105.     // orient the drag plane
    106.     if (dragPlaneNormal != Vector3.zero) {
    107.         dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * Quaternion(1, 0, 0, 1);
    108.     }
    109.     else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    110.    
    111.     //update the position of the dragzone
    112.     dragZone.transform.position = transform.position;
    113.    
    114.     dragZone.renderer.enabled = true;
    115. }
    116.  
    117. void OnMouseDrag (){
    118.     // update the plane if the target object has left it
    119.     if (dragPlane.GetDistanceToPoint(transform.position) != 0) {
    120.         // update dragplane by constructing a new one -- I should check this with a profiler
    121.         dragPlane = Plane(dragPlaneNormal, transform.position);
    122.     }
    123.    
    124.     // create a ray from the camera, through the mouse position in 3D space
    125.     mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    126.    
    127.     // if mouseRay intersects with dragPlane
    128.     float intersectDist;
    129.    
    130.     if (dragPlane.Raycast(mouseRay, intersectDist)) {
    131.         // update the world space point for the mouse position on the dragPlane
    132.         mousePos3D = mouseRay.GetPoint(intersectDist);
    133.        
    134.         // calculate the distance between the 3d mouse position and the object position
    135.         dragDistance = Mathf.Clamp((mousePos3D - transform.position).magnitude, 0, magBase);
    136.        
    137.         // calculate the force vector
    138.         if (dragDistance*magMultiplier < 1) dragDistance = 0; // this is to allow for a "no move" buffer close to the object
    139.         forceVector = mousePos3D - transform.position;
    140.         forceVector.Normalize();
    141.         forceVector *= dragDistance * magMultiplier;
    142.        
    143.         // update color the color
    144.         // calculate the percentage value of current force magnitude out of maximum
    145.         magPercent = (dragDistance * magMultiplier) / (magBase * magMultiplier);
    146.         // choose color based on how close magPercent is to either 0 or max
    147.         currentColor = noForceColor * (1-magPercent) + maxForceColor * magPercent;
    148.        
    149.         // dragzone color
    150.         dragZone.renderer.material.color = currentColor * Color(1,1,1,0.2f);
    151.        
    152.         // draw the line
    153.         Debug.DrawRay(transform.position, forceVector / magMultiplier, currentColor);
    154.     }
    155.    
    156.     //update the position of the dragzone
    157.     dragZone.transform.position = transform.position;
    158. }
    159.  
    160. void OnMouseUp (){
    161.     mouseDragging = false;
    162.    
    163.     if (overrideVelocity) {
    164.         // cancel existing velocity
    165.         rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
    166.     }
    167.    
    168.     // add new force
    169.     int snapD = 1;
    170.     if (snapDirection == SnapDir.away) snapD = -1; // if snapdirection is "away" set the force to apply in the opposite direction
    171.     rigidbody.AddForce(snapD * forceVector, forceTypeToApply);
    172.    
    173.     // cleanup
    174.     dragZone.renderer.enabled = false;
    175.    
    176.     if (pauseOnDrag) {
    177.         // un-pause the simulation
    178.         Time.timeScale = 1;
    179.     }
    180.    
    181. }
    182.  
    183. void OnGUI (){
    184.     if (mouseDragging) {
    185.         Vector2 guiMouseCoord = GUIUtility.ScreenToGUIPoint(Input.mousePosition);
    186.         GUI.Box ( new Rect(guiMouseCoord.x-30, Screen.height-guiMouseCoord.y+15, 100, 20), "force: "+Mathf.Round((forceVector).magnitude));
    187.     }
    188. }
    189.  
    190. Mesh MakeDiscMeshBrute ( float r  ){
    191.     Mesh discMesh;
    192.     Vector3[] dmVerts = new Vector3[18];
    193.     Vector3[] dmNorms = new Vector3[18];
    194.     Vector2[] dmUVs = new Vector2[18];
    195.     int[] dmTris = new int[48];
    196.     int i = 0;
    197.    
    198.     discMesh = new Mesh();
    199.    
    200.     dmVerts[0] = Vector3(0,0,0);
    201.     dmVerts[1] = Vector3(0,0,r);
    202.     dmVerts[2] = Vector3(1,0,1).normalized * r; // find the vector at the correct distance the hacky-hillbilly way!
    203.     dmVerts[3] = Vector3(r,0,0);
    204.     dmVerts[4] = Vector3(1,0,-1).normalized * r;
    205.     dmVerts[5] = Vector3(0,0,-r);
    206.     dmVerts[6] = Vector3(-1,0,-1).normalized * r;
    207.     dmVerts[7] = Vector3(-r,0,0);
    208.     dmVerts[8] = Vector3(-1,0,1).normalized * r;
    209.    
    210.     // set the other side to the same points
    211.     for (i = 0; i<dmVerts.length/2; i++) {
    212.         dmVerts[dmVerts.Length/2 + i] = dmVerts[i];
    213.     }
    214.    
    215.     for (i = 0; i<dmNorms.length; i++) {
    216.         if (i<dmNorms.length/2) dmNorms[i] = Vector3.up; // set side one to face up
    217.         else dmNorms[i] = -Vector3.up; // set side two to face down
    218.     }
    219.    
    220.     dmUVs[0] = Vector2(0,0);
    221.     dmUVs[1] = Vector2(0,r);
    222.     dmUVs[2] = Vector2(1,1).normalized * r;;
    223.     dmUVs[3] = Vector2(r,0);
    224.     dmUVs[4] = Vector2(1,-1).normalized * r;;
    225.     dmUVs[5] = Vector2(0,-r);
    226.     dmUVs[6] = Vector2(-1,-1).normalized * r;;
    227.     dmUVs[7] = Vector2(-r,0);
    228.     dmUVs[8] = Vector2(-1,1).normalized * r;;
    229.    
    230.     // set the other side to the same points
    231.     for (i = 0; i<dmUVs.length/2; i++) {
    232.         dmUVs[dmUVs.Length/2 + i] = dmUVs[i];
    233.     }
    234.    
    235.     dmTris[0] = 0;
    236.     dmTris[1] = 1;
    237.     dmTris[2] = 2;
    238.    
    239.     dmTris[3] = 0;
    240.     dmTris[4] = 2;
    241.     dmTris[5] = 3;
    242.    
    243.     dmTris[6] = 0;
    244.     dmTris[7] = 3;
    245.     dmTris[8] = 4;
    246.    
    247.     dmTris[9] = 0;
    248.     dmTris[10] = 4;
    249.     dmTris[11] = 5;
    250.    
    251.     dmTris[12] = 0;
    252.     dmTris[13] = 5;
    253.     dmTris[14] = 6;
    254.    
    255.     dmTris[15] = 0;
    256.     dmTris[16] = 6;
    257.     dmTris[17] = 7;
    258.    
    259.     dmTris[18] = 0;
    260.     dmTris[19] = 7;
    261.     dmTris[20] = 8;
    262.    
    263.     dmTris[21] = 0;
    264.     dmTris[22] = 8;
    265.     dmTris[23] = 1;
    266.    
    267.     // side two
    268.     dmTris[24] = 9;
    269.     dmTris[25] = 11;
    270.     dmTris[26] = 10;
    271.    
    272.     dmTris[27] = 9;
    273.     dmTris[28] = 12;
    274.     dmTris[29] = 11;
    275.    
    276.     dmTris[30] = 9;
    277.     dmTris[31] = 13;
    278.     dmTris[32] = 12;
    279.    
    280.     dmTris[33] = 9;
    281.     dmTris[34] = 14;
    282.     dmTris[35] = 13;
    283.    
    284.     dmTris[36] = 9;
    285.     dmTris[37] = 15;
    286.     dmTris[38] = 14;
    287.    
    288.     dmTris[39] = 9;
    289.     dmTris[40] = 16;
    290.     dmTris[41] = 15;
    291.    
    292.     dmTris[42] = 9;
    293.     dmTris[43] = 17;
    294.     dmTris[44] = 16;
    295.    
    296.     dmTris[45] = 9;
    297.     dmTris[46] = 10;
    298.     dmTris[47] = 17;
    299.    
    300.     discMesh.vertices = dmVerts;
    301.     discMesh.uv = dmUVs;
    302.     discMesh.normals = dmNorms;
    303.     discMesh.triangles = dmTris;
    304.    
    305.     return discMesh;
    306. }
    307. }
     
  8. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    How can i retrict it to 2d for a sidescroller or a top down?

    Ok, after testing it themed that it is retricted to 2D because it does not work right in my scene in wich i reassign gravity to positive 9.81 in the z axis so then i can use the smooth follow cam from the mobile standard things in wich a vector2 exist wich will not have a z axis.

    So now i have to learn how to rotate the script ;) i mean the funvtion of what the script does.
     
    Last edited: May 28, 2011
  9. SamSam

    SamSam

    Joined:
    Aug 31, 2010
    Posts:
    44
    One solution without editing the script :

    In the Rigidbody component of your gameobject > Constraints :
    Tick the Y box for Freeze Position and the X and Y boxes for Freeze Orientation.

    Then in the Drag Shot Mover Component > Drag Plane Normal :
    Set the value of 1 for the needed vectors.

    Note that these settings should be used where your gameobject axes are X for right/left, Y for up/down.
     
    Last edited: May 28, 2011
  10. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    That works! Thank you SamSam :)
    I changed the values to my new gravity.
     
  11. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    Now i only have to find out how to drag with the finger on the iphone with this script and i can make a simple jump game.
     
  12. LeadCarbonate

    LeadCarbonate

    Joined:
    Mar 10, 2011
    Posts:
    18
    Thank you for posting this SamSam! I haven't had time to get back over here in a long time. Glad the script is getting used ... and even supported!


    Is there still a demand for this script in C#? My partner ported it a while back but I never posted it. Let me know.

    I switched to C# as well in the last month and I'm very glad I did so.
     
  13. bigSky

    bigSky

    Joined:
    Jan 31, 2011
    Posts:
    114
    I'd be certainly greatful for a C# script. Wonderful work.
     
  14. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    oh yes, I would surely be thankful for a c# version. if you can it would be fantastic.
     
  15. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Another vote for a C# version. The fewer gear changes my brain has to make while working, the better.
     
  16. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    c# please :)
     
  17. Ardan

    Ardan

    Joined:
    Oct 5, 2009
    Posts:
    68
    I put together this C# version quickly. It's basically just a line by line rewrite, so there shouldn't be any problems. But if you find any, please tell me and i'll fix it.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [RequireComponent (typeof(Rigidbody))]
    5. [RequireComponent (typeof(Collider))]
    6.  
    7. public class DragShotMover : MonoBehaviour {
    8.  
    9.     /*
    10.         Drag-Shot Mover v01
    11.  
    12.         Desc: Allows force to be applied to the object by clicking that body
    13.         and dragging to designate a force vector with a maximum magnitude.
    14.  
    15.         TODO:
    16.             + set dead zone to a percentage
    17.             + add a "tension" option to the feel of the drag
    18.             + fancy, non-debug line
    19.             + add something to the disc that will make it clear how its tilted.
    20.  
    21.         Known Issues:
    22.  
    23.         Reminders / Caveats / Gotchas:
    24.             + OnMouseDown doesn't see the target object under another collider.  This is just
    25.               how Unity works.
    26.  
    27.     */
    28.  
    29.     public float magBase = 2; // this is the base magnitude and the maximum length of the line drawn in the user interface
    30.     public float magMultiplier = 5; // multiply the line length by this to allow for higher force values to be represented by shorter lines
    31.     public Vector3 dragPlaneNormal = Vector3.up; // a vector describing the orientation of the drag plan relative to world-space but centered on the target
    32.     public SnapDir snapDirection = SnapDir.away; // force is applied either toward or away from the mouse on release
    33.     public ForceMode forceTypeToApply = ForceMode.VelocityChange;
    34.  
    35.     public bool  overrideVelocity = true; // cancel the existing velocity before applying the new force
    36.     public bool  pauseOnDrag = true; // causes the simulation to pause when the object is clicked and unpause when released
    37.  
    38.     public Color noForceColor = Color.yellow; // color of the visualization helpers at force 0
    39.     public Color maxForceColor = Color.red; // color of the visualization helpers at maximum force
    40.  
    41.     public enum SnapDir {toward, away}
    42.  
    43.     private Vector3 forceVector;
    44.     private float magPercent = 0;
    45.  
    46.     private bool  mouseDragging = false;
    47.     private Vector3 mousePos3D;
    48.     private float dragDistance;
    49.     private Plane dragPlane;
    50.     private Ray mouseRay;
    51.     private GameObject dragZone;
    52.  
    53.     private string shaderString = "Transparent/Diffuse";
    54.     private Material dzMat;
    55.  
    56.     void  Start (){
    57.         Color currentColor = noForceColor;
    58.         dzMat = new Material(Shader.Find(shaderString));
    59.  
    60.         // create the dragzone visual helper
    61.         dragZone = new GameObject("dragZone_" + gameObject.name);
    62.         dragZone.AddComponent<MeshFilter>().mesh = MakeDiscMeshBrute(magBase/4);
    63.         //dragZone.GetComponent.MeshFilter.
    64.         dragZone.AddComponent<MeshRenderer>();
    65.         dragZone.renderer.enabled = false;
    66.  
    67.         dragZone.name = "dragZone_" + gameObject.name;
    68.         dragZone.transform.localScale = new Vector3(magBase*2, 0.025f, magBase*2);
    69.         dragZone.renderer.material = dzMat;
    70.         dragZone.renderer.material.color = currentColor * new Color(1,1,1,0.2f);
    71.  
    72.         // create the dragplane
    73.         dragPlane = new Plane(dragPlaneNormal, transform.position);
    74.  
    75.         // orient the drag plane
    76.         if (dragPlaneNormal != Vector3.zero) {
    77.             dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * new Quaternion(1, 0, 0, 1);
    78.         }
    79.         else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    80.  
    81.         //update the position of the dragzone
    82.         dragZone.transform.position = transform.position;  
    83.     }
    84.  
    85.     void  OnMouseDown (){
    86.         mouseDragging = true;
    87.  
    88.         if (pauseOnDrag) {
    89.             // pause the simulation
    90.             Time.timeScale = 0;
    91.         }
    92.         // update the dragplane
    93.         dragPlane = new Plane(dragPlaneNormal, transform.position);
    94.  
    95.         // orient the drag plane
    96.         if (dragPlaneNormal != Vector3.zero) {
    97.             dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * new Quaternion(1, 0, 0, 1);
    98.         }
    99.         else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
    100.  
    101.         //update the position of the dragzone
    102.         dragZone.transform.position = transform.position;
    103.  
    104.         dragZone.renderer.enabled = true;
    105.     }
    106.  
    107.    
    108.  
    109.     void  OnMouseDrag (){
    110.         Color currentColor = noForceColor;
    111.         // update the plane if the target object has left it
    112.         if (dragPlane.GetDistanceToPoint(transform.position) != 0) {
    113.             // update dragplane by constructing a new one -- I should check this with a profiler
    114.             dragPlane = new Plane(dragPlaneNormal, transform.position);
    115.         }
    116.  
    117.         // create a ray from the camera, through the mouse position in 3D space
    118.         mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    119.  
    120.         // if mouseRay intersects with dragPlane
    121.         float intersectDist = 0.0f;
    122.  
    123.         if (dragPlane.Raycast(mouseRay, out intersectDist)) {
    124.             // update the world space point for the mouse position on the dragPlane
    125.             mousePos3D = mouseRay.GetPoint(intersectDist);
    126.  
    127.             // calculate the distance between the 3d mouse position and the object position
    128.             dragDistance = Mathf.Clamp((mousePos3D - transform.position).magnitude, 0, magBase);
    129.  
    130.             // calculate the force vector
    131.             if (dragDistance*magMultiplier < 1) dragDistance = 0; // this is to allow for a "no move" buffer close to the object
    132.             forceVector = mousePos3D - transform.position;
    133.             forceVector.Normalize();
    134.             forceVector *= dragDistance * magMultiplier;
    135.  
    136.             // update color the color
    137.             // calculate the percentage value of current force magnitude out of maximum
    138.             magPercent = (dragDistance * magMultiplier) / (magBase * magMultiplier);
    139.             // choose color based on how close magPercent is to either 0 or max
    140.             currentColor = noForceColor * (1-magPercent) + maxForceColor * magPercent;
    141.  
    142.             // dragzone color
    143.             dragZone.renderer.material.color = currentColor * new Color(1,1,1,0.2f);
    144.  
    145.             // draw the line
    146.             Debug.DrawRay(transform.position, forceVector / magMultiplier, currentColor);
    147.         }
    148.  
    149.         //update the position of the dragzone
    150.         dragZone.transform.position = transform.position;
    151.     }
    152.  
    153.     void  OnMouseUp (){
    154.         mouseDragging = false;
    155.  
    156.         if (overrideVelocity) {
    157.             // cancel existing velocity
    158.             rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
    159.  
    160.         }
    161.  
    162.         // add new force
    163.         int snapD = 1;
    164.         if (snapDirection == SnapDir.away) snapD = -1; // if snapdirection is "away" set the force to apply in the opposite direction
    165.         rigidbody.AddForce(snapD * forceVector, forceTypeToApply);
    166.  
    167.         // cleanup
    168.         dragZone.renderer.enabled = false;
    169.  
    170.         if (pauseOnDrag) {
    171.             // un-pause the simulation
    172.             Time.timeScale = 1;
    173.         }
    174.  
    175.     }
    176.  
    177.     void  OnGUI (){
    178.         if (mouseDragging) {
    179.             Vector2 guiMouseCoord = GUIUtility.ScreenToGUIPoint(Input.mousePosition);
    180.             GUI.Box ( new Rect(guiMouseCoord.x-30, Screen.height-guiMouseCoord.y+15, 100, 20), "force: "+Mathf.Round((forceVector).magnitude));
    181.         }
    182.     }
    183.  
    184.     Mesh MakeDiscMeshBrute ( float r  ){
    185.         Mesh discMesh;
    186.         Vector3[] dmVerts = new Vector3[18];
    187.         Vector3[] dmNorms = new Vector3[18];
    188.         Vector2[] dmUVs = new Vector2[18];
    189.         int[] dmTris = new int[48];
    190.         int i = 0;
    191.  
    192.         discMesh = new Mesh();
    193.  
    194.         dmVerts[0] = new Vector3(0,0,0);
    195.         dmVerts[1] = new Vector3(0,0,r);
    196.         dmVerts[2] = new Vector3(1,0,1).normalized * r; // find the vector at the correct distance the hacky-hillbilly way!
    197.         dmVerts[3] = new Vector3(r,0,0);
    198.         dmVerts[4] = new Vector3(1,0,-1).normalized * r;
    199.         dmVerts[5] = new Vector3(0,0,-r);
    200.         dmVerts[6] = new Vector3(-1,0,-1).normalized * r;
    201.         dmVerts[7] = new Vector3(-r,0,0);
    202.         dmVerts[8] = new Vector3(-1,0,1).normalized * r;
    203.  
    204.         // set the other side to the same points
    205.         for (i = 0; i<dmVerts.Length/2; i++) {
    206.             dmVerts[dmVerts.Length/2 + i] = dmVerts[i];
    207.         }
    208.         for (i = 0; i<dmNorms.Length; i++) {
    209.             if (i<dmNorms.Length/2) dmNorms[i] = Vector3.up; // set side one to face up
    210.             else dmNorms[i] = -Vector3.up; // set side two to face down
    211.         }
    212.  
    213.         dmUVs[0] = new Vector2(0,0);
    214.         dmUVs[1] = new Vector2(0,r);
    215.         dmUVs[2] = new Vector2(1,1).normalized * r;;
    216.         dmUVs[3] = new Vector2(r,0);
    217.         dmUVs[4] = new Vector2(1,-1).normalized * r;;
    218.         dmUVs[5] = new Vector2(0,-r);
    219.         dmUVs[6] = new Vector2(-1,-1).normalized * r;;
    220.         dmUVs[7] = new Vector2(-r,0);
    221.         dmUVs[8] = new Vector2(-1,1).normalized * r;;
    222.  
    223.         // set the other side to the same points
    224.         for (i = 0; i<dmUVs.Length/2; i++) {
    225.             dmUVs[dmUVs.Length/2 + i] = dmUVs[i];
    226.         }
    227.  
    228.         dmTris[0] = 0;
    229.         dmTris[1] = 1;
    230.         dmTris[2] = 2;
    231.  
    232.         dmTris[3] = 0;
    233.         dmTris[4] = 2;
    234.         dmTris[5] = 3;
    235.  
    236.         dmTris[6] = 0;
    237.         dmTris[7] = 3;
    238.         dmTris[8] = 4;
    239.  
    240.         dmTris[9] = 0;
    241.         dmTris[10] = 4;
    242.         dmTris[11] = 5;
    243.  
    244.         dmTris[12] = 0;
    245.         dmTris[13] = 5;
    246.         dmTris[14] = 6;
    247.  
    248.         dmTris[15] = 0;
    249.         dmTris[16] = 6;
    250.         dmTris[17] = 7;
    251.  
    252.         dmTris[18] = 0;
    253.         dmTris[19] = 7;
    254.         dmTris[20] = 8;
    255.  
    256.         dmTris[21] = 0;
    257.         dmTris[22] = 8;
    258.         dmTris[23] = 1;
    259.  
    260.         // side two
    261.         dmTris[24] = 9;
    262.         dmTris[25] = 11;
    263.         dmTris[26] = 10;
    264.  
    265.         dmTris[27] = 9;
    266.         dmTris[28] = 12;
    267.         dmTris[29] = 11;
    268.  
    269.         dmTris[30] = 9;
    270.         dmTris[31] = 13;
    271.         dmTris[32] = 12;
    272.  
    273.         dmTris[33] = 9;
    274.         dmTris[34] = 14;
    275.         dmTris[35] = 13;
    276.  
    277.         dmTris[36] = 9;
    278.         dmTris[37] = 15;
    279.         dmTris[38] = 14;
    280.  
    281.         dmTris[39] = 9;
    282.         dmTris[40] = 16;
    283.         dmTris[41] = 15;
    284.  
    285.         dmTris[42] = 9;
    286.         dmTris[43] = 17;
    287.         dmTris[44] = 16;
    288.  
    289.         dmTris[45] = 9;
    290.         dmTris[46] = 10;
    291.         dmTris[47] = 17;
    292.  
    293.         discMesh.vertices = dmVerts;
    294.         discMesh.uv = dmUVs;
    295.         discMesh.normals = dmNorms;
    296.         discMesh.triangles = dmTris;
    297.  
    298.         return discMesh;
    299.     }
    300. }
     
    Last edited: May 31, 2011
    karen_ann and Xain like this.
  18. LeadCarbonate

    LeadCarbonate

    Joined:
    Mar 10, 2011
    Posts:
    18
    Wow! Thanks mate!
     
  19. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    excellent, thanks Ardan, very helpful
     
  20. IndieStudio

    IndieStudio

    Joined:
    May 12, 2011
    Posts:
    60
    Is it possible to someone produce a simple scene (package) with an example?
     
  21. joel

    joel

    Joined:
    Jun 12, 2010
    Posts:
    117
    IndieStudio. just create a cube with a rigidbody, then add the script. and click+drag it.
    no point in making a scene/package for it.
     
  22. IndieStudio

    IndieStudio

    Joined:
    May 12, 2011
    Posts:
    60
    Yes, of course. My bad.
     
  23. LeadCarbonate

    LeadCarbonate

    Joined:
    Mar 10, 2011
    Posts:
    18
    Sure, I can do that if somebody doesn't beat me to it.
     
  24. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    Do someone know how to make a dotted line with an arc that points to the direction on where the object will land like in angry bird?
     
  25. Ardan

    Ardan

    Joined:
    Oct 5, 2009
    Posts:
    68
    I think that the easiest way would be to use Vectrosity, which you can buy from the Asset Store.
     
  26. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    @LeadCarbonate
    You mentioned this in your script:

    + add a "tension" option to the feel of the drag

    What will it do and will we get this as a script Addition?
    It sound interesting!
     
  27. JRulkiewicz

    JRulkiewicz

    Joined:
    Sep 5, 2011
    Posts:
    18
    Nice work! I am a novice programmer, but I'm wondering what would be needed in order to add an "arc" or some sort of trajectory to it, rather than the "line-drive" motion it goes now?
     
  28. JRulkiewicz

    JRulkiewicz

    Joined:
    Sep 5, 2011
    Posts:
    18
    I might have figured it out... if I change the "Drag Plane Normal" so that X, Y and Z = 1, when I pull back, I can get it to launch and go air-born, but it seems sporadic. I'll have to play with it a little more when I get home.
     
  29. Catlard

    Catlard

    Joined:
    Sep 23, 2011
    Posts:
    3
    Hey, hate to be greedy, but I'm very interested in using this script for a game--but I need it to do something a bit different, and I can't figure out how to make it work just by fiddling with the code. Basically, I'd like for the user to be able to click anywhere on the screen and bring up the drag plane, and then apply the force as usual. Because the object I'm dragging is quite small...and hard to click on.

    Any ideas about how to change the code?

    Cheers.
     
  30. jblazer

    jblazer

    Joined:
    Apr 17, 2009
    Posts:
    31
    This is a great script... Thank you so much for the contribution to the community. I'm tracking down what looks like a minor bug though - maybe someone can help with this. The scene is just a box in a 2d environment that you can click, drag, and launch to your hearts content. As you're launching the little box around though, you'll notice if you get the box toward the left side of the screen near the wall, and pull back to launch it to the right it will launch in the opposite direction that you intended. It only happens there to the left which makes me think perhaps a collider is interacting with it. Doesn't seem to happen on the right side though. Need to dig a little deeper into the script... Anyone else have ideas?

    Josh
     
    Last edited: Oct 6, 2011
  31. jblazer

    jblazer

    Joined:
    Apr 17, 2009
    Posts:
    31
    Well I I found the problem... almost immediately after I posted. This only happens when the object being launched enters negative world space (x,y,z)... Maybe something to keep in mind... In the original scene I had x going into negative over toward the left of the screen...

    Here's an simple scene where it's all working... You'll notice here that everything is setup so that the box never goes into negative x or y territory. z is constrained...

    I'm looking for a way now to constrain the rotation of the object to the trajectory... Anyone have any ideas on pulling that off? I may need to brush up on some math here...

    Again thanks for the script. very helpful.
     

    Attached Files:

    Last edited: Oct 6, 2011
  32. keith patience

    keith patience

    Joined:
    Mar 25, 2011
    Posts:
    84
    Soz for posting here guys but i am a 3d artist with an idea for a game that would involve this piece of scripting. If any one is interested or looking for a project to use this in please feel free to pm me
     
  33. Logistic-Win

    Logistic-Win

    Joined:
    Apr 4, 2009
    Posts:
    107
    Did anyone ever get this working on a touchscreen?
     
  34. 8r3nd4n

    8r3nd4n

    Joined:
    Sep 10, 2011
    Posts:
    30
    Thanks for the script, its great for programming beginners to get a grip on some things.
    I have tried tinkering with it a bit to get it behaving how I want but so far no luck.
    What I wish to do is have the launch point constrained to a point in the world (lets say 0,0,0), and when you drag the mouse, it will increase the force relative to how far from the origin point it is and always fire in the direction from dragged point through origin. So if you dragged the mouse to the top right corner, it would fire in a direction to the bottom left of the screen. The movement would also need to be constrained in x and y directions, and the z would always be set at 1 or 2 behind the origin point.

    Any help appreciated
     
  35. Logistic-Win

    Logistic-Win

    Joined:
    Apr 4, 2009
    Posts:
    107
    I was able to successfully convert this for iOS touch screens using JS... if anyone needs a copy of my working script... please feel free to message me.
     
  36. khaosenygma

    khaosenygma

    Joined:
    May 5, 2011
    Posts:
    27
    If I wanted it to launch instantiations of an object.. like after letting go it creates and fires an object. how would I do that?
     
  37. skywalkerbr

    skywalkerbr

    Joined:
    Oct 17, 2008
    Posts:
    1
    Can you send me it?
    Thank you.
     
  38. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Thanks for providing this, really great!!!
     
  39. Doucettej

    Doucettej

    Joined:
    Jan 18, 2010
    Posts:
    85
    I would love to get the IOS touch screen code / port for this script!@ :) This is a great script by the way! Thank you very much for sharing it!

    Jason
     
  40. kerrickchan

    kerrickchan

    Joined:
    Aug 11, 2012
    Posts:
    1
    push it . i test it in JavaScript version. it run very well =)
     
  41. Phoenix7

    Phoenix7

    Joined:
    Mar 18, 2014
    Posts:
    22
    how do you importet for ios, android? i understud the input.touch and so..how i can change the code for playable on android?
     
  42. Phoenix7

    Phoenix7

    Joined:
    Mar 18, 2014
    Posts:
    22
    Yes, please send it to me.. :) Or explain me, how i can rewrite/change for android :)
     
  43. sylar93

    sylar93

    Joined:
    Nov 16, 2013
    Posts:
    1
    Hello . I want to change the hexagon range circle to a dotted line like angry birds . Any ideas ?
     
  44. Julie Raiyani

    Julie Raiyani

    Joined:
    Jun 26, 2014
    Posts:
    2
    Hello, @Jblazer

    you code was awesome , thanks for the code , I have one query is this code is working with android and iPhone ?? ! as my trial that was not working with android and iPhone , will you please help me out.

    your help would be
    appreciable, thanks again for wonderful post !!!

    Thanks,
    Julie.
     
  45. Logistic-Win

    Logistic-Win

    Joined:
    Apr 4, 2009
    Posts:
    107

    Here is a converted version that works for iPhone... not tested on Android but most likely works fine if you update the deprecated functions. It's an old work, incomplete and a lot of stuff has been commented out in the middle of testing but I know it works.


    http://www.logisticwin.com/DragShot.js

    Hope it helps you out!
     
  46. Julie Raiyani

    Julie Raiyani

    Joined:
    Jun 26, 2014
    Posts:
    2
    hello Logistic win,

    Thank you so much for very quick reply,
    there are some errors in the script which you provided.

    please find the screen shot.

    Thanks again for quick reply

    Thanks,
    Julie
     

    Attached Files:

  47. SeriousTangents

    SeriousTangents

    Joined:
    Nov 1, 2013
    Posts:
    12
    A very quick thank you to Ardan for the C# version of the code he provided, as well as thanks to whomever initially coded this.. After nearly 24 hours of trying to figure out the best way to fire a golf ball in my miniature golf game, this script is actually giving me more control than many of the other scripts I have tried to use. Thanks again.

    Joseph.
     
  48. kingflurkel

    kingflurkel

    Joined:
    Jan 11, 2015
    Posts:
    1
    Still have this? Am looking for ios / android version. Thanks!
     
  49. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    Hi all, I edited C# mode to not negative move. if you drag left it moves left, if you drag right it moves right. How can I deal with Y and Z axes? If I drag up/down and forward/backward please help. thanks
     
  50. SonEvil

    SonEvil

    Joined:
    Jul 29, 2015
    Posts:
    11
    someone please share this script for android ?