Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Easy Touch

Discussion in 'Assets and Asset Store' started by Hedgehog-Team, May 8, 2012.

  1. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Ah oke well i got it working with a simple touch gesture. Now i got another question for you. I have an object which is rotatable through the z value and through the y value.
    But when my object is rotated around (on its head) and i swipe right the object rotates left instead of right, and vice versa. What's the easiest way to fix this?
     
  2. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    Can you post the script that write to do your rotation ?
     
  3. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Here you go:

    Code (csharp):
    1.  
    2. #pragma strict
    3. public static var SC : SwipeControls;
    4.  
    5. private var vetPen : GameObject;
    6. private var speed : float = 20;
    7. private var timeEase = -3;
    8. private var swipeAngle;
    9.  
    10. //Inertia Variables
    11. private var rotateVelocityX : float = 0;
    12. private var itemTimeTouchPhaseEnded : float;
    13. private var timeTouchPhaseEnded : float;
    14. private var inertiaDuration : float = 2.0f;
    15. private var scrollVelocity : float = 0;
    16. private var scrollPosition : Vector2 = Vector2.zero;
    17. private var rotationRate : float = 0.5f;
    18. private var inertiaValue : float;
    19.  
    20. private var vetPenKit : GameObject;
    21. private var summaryPanel : GameObject;
    22.  
    23.  
    24. function Awake()
    25. {
    26.     SC = this;
    27.     vetPen = GameObject.Find("VetPen");
    28.     vetPenKit = GameObject.Find("StarterKit");
    29.     summaryPanel = GameObject.Find("Summary Panel");
    30. }
    31.  
    32. function Update()
    33. {
    34.     CheckIfHorizontal();
    35.     if(Input.touchCount == 0  !MenuManager.MM.getScreenActive())
    36.     {
    37.         Inertia();
    38.     }
    39.    
    40. }
    41.  
    42. function On_Swipe(gesture : Gesture)
    43. {
    44.     if(gesture.swipe == EasyTouch.SwipeType.Right  MenuManager.MM.getTestimonialActive())
    45.     {
    46.         if(vetPenKit.activeSelf)
    47.             iTween.MoveTo(vetPenKit, {"x": 2200, "time": 1, "isLocal": true, "oncompletetarget": gameObject, "oncomplete": "TurnOff"});
    48.            
    49.         if(summaryPanel.activeSelf)
    50.             iTween.MoveTo(summaryPanel, {"x": 2200, "time": 1, "isLocal": true, "oncompletetarget": gameObject, "oncomplete": "TurnOff"});
    51.     }
    52.    
    53.     if(EasyTouch.SwipeType.Left  !MenuManager.MM.getScreenActive())
    54.     {
    55.         rotateVelocityX = 0.0;
    56.         vetPen.transform.Rotate(new Vector3(0, -1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    57.         CheckIfHorizontal();
    58.     }
    59.     else if(EasyTouch.SwipeType.Right  !MenuManager.MM.getScreenActive())
    60.     {
    61.         CheckIfHorizontal();
    62.         rotateVelocityX = 0.0;
    63.         vetPen.transform.Rotate(new Vector3(0, 1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    64.     }
    65.    
    66.     if(EasyTouch.SwipeType.Up || EasyTouch.SwipeType.Down !MenuManager.MM.getScreenActive())
    67.     {
    68.         CheckIfHorizontal();
    69.         rotateVelocityX = 0.0;
    70.         vetPen.transform.Rotate(new Vector3(0, 0, 1) * gesture.deltaPosition.y * Time.deltaTime * speed);
    71.     }
    72. }
    73.  
    74. function On_SwipeEnd(gesture : Gesture)
    75. {
    76.     CheckIfHorizontal();
    77.  
    78.     if(gesture.swipe == EasyTouch.SwipeType.Left)
    79.     {
    80.         if(Mathf.Abs(gesture.deltaPosition.x) >= 3)
    81.         {
    82.             rotateVelocityX = gesture.deltaPosition.x / gesture.deltaTime;
    83.         }
    84.         itemTimeTouchPhaseEnded = Time.time;
    85.     }
    86.    
    87.     if(gesture.swipe == EasyTouch.SwipeType.Right)
    88.     {
    89.         if(Mathf.Abs(gesture.deltaPosition.x) >= 3)
    90.         {
    91.             rotateVelocityX = gesture.deltaPosition.x / gesture.deltaTime;
    92.         }
    93.         itemTimeTouchPhaseEnded = Time.time;
    94.     }
    95. }
    96.  
    97. function Inertia()
    98. {
    99.     CheckIfHorizontal();
    100.     if(scrollVelocity != 0.0)
    101.     {
    102.         CheckIfHorizontal();
    103.         var t : float = (Time.time - timeTouchPhaseEnded) / inertiaDuration;
    104.         var frameVelocity : float = Mathf.Lerp(scrollVelocity, 0, t);
    105.        
    106.         scrollPosition.x -= frameVelocity * Time.deltaTime;
    107.        
    108.         if(t >= inertiaDuration)
    109.             scrollVelocity = 0.0f;
    110.     }
    111.    
    112.     if(rotateVelocityX != 0.0f)
    113.     {
    114.         CheckIfHorizontal();
    115.         var ty : float = (Time.time - itemTimeTouchPhaseEnded) / inertiaDuration;
    116.         var XVelocity : float = Mathf.Lerp(rotateVelocityX, 0, ty);
    117.     }
    118.    
    119.     if(ty >= inertiaDuration)
    120.     {
    121.         CheckIfHorizontal();
    122.         rotateVelocityX = 0.0f;
    123.     }
    124.    
    125.     if(XVelocity > 1500)
    126.     {
    127.         XVelocity = 1500;
    128.     }
    129.        
    130.     if(XVelocity < -1500)
    131.     {
    132.         XVelocity = -1500;
    133.     }
    134.    
    135.     inertiaValue = -XVelocity * Time.deltaTime * rotationRate;
    136.    
    137.     if(inertiaValue != inertiaValue)
    138.     {
    139.     }
    140.     else
    141.     {
    142.         CheckIfHorizontal();
    143.         vetPen.transform.Rotate(0, inertiaValue, 0);
    144.         CheckIfHorizontal();
    145.     }
    146.        
    147.    
    148. }
    149.  
    150. function TurnOff()
    151. {
    152.     MenuManager.MM.summaryClose();
    153.     MenuManager.MM.starterKitClose();
    154.     MenuManager.MM.setTestmonialActive(false);
    155. }
    156.  
    157. function CheckIfHorizontal()
    158. {
    159.     if(vetPen.transform.eulerAngles.x != 0 || vetPen.transform.rotation.x != 0)
    160.         vetPen.transform.eulerAngles.x = 0;
    161. }
    162.  
    163.  
     
  4. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    For me you have just to inverse Y axis value

    Code (csharp):
    1. if(EasyTouch.SwipeType.Left  !MenuManager.MM.getScreenActive())
    2.  
    3.     {
    4.  
    5.         rotateVelocityX = 0.0;
    6.  
    7.         vetPen.transform.Rotate(new Vector3(0, 1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    8.  
    9.         CheckIfHorizontal();
    10.  
    11.     }
    12. else if(EasyTouch.SwipeType.Right  !MenuManager.MM.getScreenActive())
    13.  
    14.     {
    15.  
    16.         CheckIfHorizontal();
    17.  
    18.         rotateVelocityX = 0.0;
    19.  
    20.         vetPen.transform.Rotate(new Vector3(0, -1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    21.  
    22.     }

    Do the same inverse for your inertia.
     
  5. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Yes i have to reverse it but only when the models z rotation is at a higher rate then 0.5 i think. But when i do something like:

    Code (csharp):
    1.  
    2. if(EasyTouch.SwipeType.Left  !MenuManager.MM.getScreenActive())
    3. {
    4.         if(vetPen.transform.rotate.z > 0.5)
    5.         {
    6.                  rotateVelocityX = 0.0;
    7.                  vetPen.transform.Rotate(new Vector3(0, -1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    8.                  CheckIfHorizontal();
    9.         }
    10.         else
    11.         {
    12.                   rotateVelocityX = 0.0;
    13.                   vetPen.transform.Rotate(new Vector3(0, 1, 0) * gesture.deltaPosition.x * Time.deltaTime * speed);
    14.                   CheckIfHorizontal();
    15.         }
    16.  
    17. }
    18.  
    But then i get some weird jittering when approaching the 0.5 z value
     
  6. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Do you have a skype account ?
     
  7. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi,

    Yes i have skype i'll PM you my skype name
     
  8. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
  9. orokborokhulu

    orokborokhulu

    Joined:
    Sep 20, 2012
    Posts:
    9
    Ok, Nicolas

    That's allright, I will try to figure out by myself. hmmm if you need 1 or 3 days to do this, maybe i need 1 or 3 weeks... hehe :D :D :D

    thanks
     
  10. ShaneStevens

    ShaneStevens

    Joined:
    Nov 16, 2012
    Posts:
    14
    I often find I need to find the current state of the Finger structs, which I can't get at outside of an event callback, so I added this to EasyTouch:

    Code (csharp):
    1.  
    2.     public static Finger GetFinger(int fingerIndex) {
    3.         return instance.fingers[fingerIndex];
    4.     }
    5.  
    this way I can do this:

    Code (csharp):
    1.  
    2. Vector2 p0 = EasyTouch.GetFinger (0).position;
    3. Vector2 p1 = EasyTouch.GetFinger (1).position;
    4.  
    I'm not sure if this is recommended, but it's helpful so would be nice to see included in the API.

    Cheers,
    Shane
     
  11. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    For orokborokhulu : It's take less time, but actualy I don't have a lot of time :)

    For ShaneStevens : It's very good idea, but can improve your code like this

    Code (csharp):
    1. public static Finger GetFinger(int fingerIndex) {
    2.  
    3.         if  ( instance.fingers[fingerIndex]!=null){
    4.                  return instance.fingers[fingerIndex];
    5.         }
    6.       else{
    7.                return null;
    8.       }
    9.  
    10.     }
     
  12. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    Important information for EasyTouch users with Android :
    There is a little bug in Unity that increased fingerId by one every time app is returned from the background.

    I warned Unity team of this bug, here is their response:

     
  13. MichelleAdams

    MichelleAdams

    Joined:
    Feb 15, 2013
    Posts:
    1
    My husband asked me to file fraud charges against Hedgehog and Unity through the company I work for (Paypal).
    I reluctantly (at first) did so, only to find dozens of fraud charges pending against them over the past few days, and
    I see you had all the negative reviews removed again. Unity will probably have their account locked during a thorough investigation, and Hedgehog Team will be likely investigated under their own international Paypal account.

    I have asked him, and the other three dozen claimants to not leave any more feedback until the fraud charges are complete. There will likely be a 100% refund rate to anyone who files a Paypal claim from now until February 21st, so if anyone else had problems with these sellers, don't hesitate to file a dispute and you are guaranteed an extenuating circumstance refund although we don't normally refund for services.
    You must file a dispute within 45 days https://www.paypal.com/us/cgi-bin/webscr?cmd=_complaint-view&nav=0.4
     
  14. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Michelle

    Once again we still do not understand the anger you have against us. If your review has been removed is that Team Unity doesn't consider as correct.

    In a year of existence, it is the first time it happens ...
    To date, there is no person who has asked to be reimbursed for EasyTouch, and no complaint was filed against us.

    Once again you spread false accusations

    If you want a refund, the request is to be done in Unity, it is provided for in their agreement. Because as you know the payment is made in Unity.

    Paypal doesn't know Hedgehog Team.

    Edit : The one start of your husband is take into account because, now we only have 4 stars (5 before the review)
     
    Last edited: Feb 15, 2013
  15. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    For orokborokhulu

    To use 3d Person Controller Prefab that coming with Standard Assets, what I do :

    * I modified ThirdPersonCamera.js script

    1 - Add a new public variable of type EasyJoystick, to drop your joystick on it

    2 - I modified UpdateSmoothedMovementDirection() method
    Code (csharp):
    1.          // Original script
    2.     //var v = Input.GetAxisRaw("Vertical");
    3.     //var h = Input.GetAxisRaw("Horizontal");
    4.    
    5.     // for EasyJoystick
    6.     var h = myJoy.JoystickAxis.x;
    7.     var v = myJoy.JoystickAxis.y;
    3 - I modified IsMoving() method
    Code (csharp):
    1.     // Original script
    2.     //return Mathf.Abs(Input.GetAxisRaw("Vertical")) + Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5;
    3.    
    4.     // For EasyJoystick
    5.     return Mathf.Abs(myJoy.JoystickAxis.x) + Mathf.Abs(myJoy.JoystickAxis.y) > 0.5;

    Take time : 2 minutes

    Below the script :

    Code (csharp):
    1.  
    2. // Require a character controller to be attached to the same game object
    3. @script RequireComponent(CharacterController)
    4.  
    5. // New public variable for EasyJoystick
    6. public var myJoy:EasyJoystick;
    7.  
    8. public var idleAnimation : AnimationClip;
    9. public var walkAnimation : AnimationClip;
    10. public var runAnimation : AnimationClip;
    11. public var jumpPoseAnimation : AnimationClip;
    12.  
    13. public var walkMaxAnimationSpeed : float = 0.75;
    14. public var trotMaxAnimationSpeed : float = 1.0;
    15. public var runMaxAnimationSpeed : float = 1.0;
    16. public var jumpAnimationSpeed : float = 1.15;
    17. public var landAnimationSpeed : float = 1.0;
    18.  
    19. private var _animation : Animation;
    20.  
    21. enum CharacterState {
    22.     Idle = 0,
    23.     Walking = 1,
    24.     Trotting = 2,
    25.     Running = 3,
    26.     Jumping = 4,
    27. }
    28.  
    29. private var _characterState : CharacterState;
    30.  
    31. // The speed when walking
    32. var walkSpeed = 2.0;
    33. // after trotAfterSeconds of walking we trot with trotSpeed
    34. var trotSpeed = 4.0;
    35. // when pressing "Fire3" button (cmd) we start running
    36. var runSpeed = 6.0;
    37.  
    38. var inAirControlAcceleration = 3.0;
    39.  
    40. // How high do we jump when pressing jump and letting go immediately
    41. var jumpHeight = 0.5;
    42.  
    43. // The gravity for the character
    44. var gravity = 20.0;
    45. // The gravity in controlled descent mode
    46. var speedSmoothing = 10.0;
    47. var rotateSpeed = 500.0;
    48. var trotAfterSeconds = 3.0;
    49.  
    50. var canJump = true;
    51.  
    52. private var jumpRepeatTime = 0.05;
    53. private var jumpTimeout = 0.15;
    54. private var groundedTimeout = 0.25;
    55.  
    56. // The camera doesnt start following the target immediately but waits for a split second to avoid too much waving around.
    57. private var lockCameraTimer = 0.0;
    58.  
    59. // The current move direction in x-z
    60. private var moveDirection = Vector3.zero;
    61. // The current vertical speed
    62. private var verticalSpeed = 0.0;
    63. // The current x-z move speed
    64. private var moveSpeed = 0.0;
    65.  
    66. // The last collision flags returned from controller.Move
    67. private var collisionFlags : CollisionFlags;
    68.  
    69. // Are we jumping? (Initiated with jump button and not grounded yet)
    70. private var jumping = false;
    71. private var jumpingReachedApex = false;
    72.  
    73. // Are we moving backwards (This locks the camera to not do a 180 degree spin)
    74. private var movingBack = false;
    75. // Is the user pressing any keys?
    76. private var isMoving = false;
    77. // When did the user start walking (Used for going into trot after a while)
    78. private var walkTimeStart = 0.0;
    79. // Last time the jump button was clicked down
    80. private var lastJumpButtonTime = -10.0;
    81. // Last time we performed a jump
    82. private var lastJumpTime = -1.0;
    83.  
    84.  
    85. // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
    86. private var lastJumpStartHeight = 0.0;
    87.  
    88.  
    89. private var inAirVelocity = Vector3.zero;
    90.  
    91. private var lastGroundedTime = 0.0;
    92.  
    93.  
    94. private var isControllable = true;
    95.  
    96. function Awake ()
    97. {
    98.     moveDirection = transform.TransformDirection(Vector3.forward);
    99.    
    100.     _animation = GetComponent(Animation);
    101.     if(!_animation)
    102.         Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
    103.    
    104.     /*
    105. public var idleAnimation : AnimationClip;
    106. public var walkAnimation : AnimationClip;
    107. public var runAnimation : AnimationClip;
    108. public var jumpPoseAnimation : AnimationClip;  
    109.     */
    110.     if(!idleAnimation) {
    111.         _animation = null;
    112.         Debug.Log("No idle animation found. Turning off animations.");
    113.     }
    114.     if(!walkAnimation) {
    115.         _animation = null;
    116.         Debug.Log("No walk animation found. Turning off animations.");
    117.     }
    118.     if(!runAnimation) {
    119.         _animation = null;
    120.         Debug.Log("No run animation found. Turning off animations.");
    121.     }
    122.     if(!jumpPoseAnimation  canJump) {
    123.         _animation = null;
    124.         Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
    125.     }
    126.            
    127. }
    128.  
    129.  
    130. function UpdateSmoothedMovementDirection ()
    131. {
    132.     var cameraTransform = Camera.main.transform;
    133.     var grounded = IsGrounded();
    134.    
    135.     // Forward vector relative to the camera along the x-z plane   
    136.     var forward = cameraTransform.TransformDirection(Vector3.forward);
    137.     forward.y = 0;
    138.     forward = forward.normalized;
    139.  
    140.     // Right vector relative to the camera
    141.     // Always orthogonal to the forward vector
    142.     var right = Vector3(forward.z, 0, -forward.x);
    143.  
    144.     // Original scropt
    145.     //var v = Input.GetAxisRaw("Vertical");
    146.     //var h = Input.GetAxisRaw("Horizontal");
    147.    
    148.     // With EasyJoystick
    149.     var h = myJoy.JoystickAxis.x;
    150.     var v = myJoy.JoystickAxis.y;
    151.    
    152.     Debug.Log(v);
    153.  
    154.     // Are we moving backwards or looking backwards
    155.     if (v < -0.2)
    156.         movingBack = true;
    157.     else
    158.         movingBack = false;
    159.    
    160.     var wasMoving = isMoving;
    161.     isMoving = Mathf.Abs (h) > 0.1 || Mathf.Abs (v) > 0.1;
    162.        
    163.     // Target direction relative to the camera
    164.     var targetDirection = h * right + v * forward;
    165.    
    166.     // Grounded controls
    167.     if (grounded)
    168.     {
    169.         // Lock camera for short period when transitioning moving  standing still
    170.         lockCameraTimer += Time.deltaTime;
    171.         if (isMoving != wasMoving)
    172.             lockCameraTimer = 0.0;
    173.  
    174.         // We store speed and direction seperately,
    175.         // so that when the character stands still we still have a valid forward direction
    176.         // moveDirection is always normalized, and we only update it if there is user input.
    177.         if (targetDirection != Vector3.zero)
    178.         {
    179.             // If we are really slow, just snap to the target direction
    180.             if (moveSpeed < walkSpeed * 0.9  grounded)
    181.             {
    182.                 moveDirection = targetDirection.normalized;
    183.             }
    184.             // Otherwise smoothly turn towards it
    185.             else
    186.             {
    187.                 moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
    188.                
    189.                 moveDirection = moveDirection.normalized;
    190.             }
    191.         }
    192.        
    193.         // Smooth the speed based on the current target direction
    194.         var curSmooth = speedSmoothing * Time.deltaTime;
    195.        
    196.         // Choose target speed
    197.         //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
    198.         var targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0);
    199.    
    200.         _characterState = CharacterState.Idle;
    201.        
    202.         // Pick speed modifier
    203.         if (Input.GetKey (KeyCode.LeftShift) | Input.GetKey (KeyCode.RightShift))
    204.         {
    205.             targetSpeed *= runSpeed;
    206.             _characterState = CharacterState.Running;
    207.         }
    208.         else if (Time.time - trotAfterSeconds > walkTimeStart)
    209.         {
    210.             targetSpeed *= trotSpeed;
    211.             _characterState = CharacterState.Trotting;
    212.         }
    213.         else
    214.         {
    215.             targetSpeed *= walkSpeed;
    216.             _characterState = CharacterState.Walking;
    217.         }
    218.        
    219.         moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
    220.        
    221.         // Reset walk time start when we slow down
    222.         if (moveSpeed < walkSpeed * 0.3)
    223.             walkTimeStart = Time.time;
    224.     }
    225.     // In air controls
    226.     else
    227.     {
    228.         // Lock camera while in air
    229.         if (jumping)
    230.             lockCameraTimer = 0.0;
    231.  
    232.         if (isMoving)
    233.             inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration;
    234.     }
    235.    
    236.  
    237.        
    238. }
    239.  
    240.  
    241. function ApplyJumping ()
    242. {
    243.     // Prevent jumping too fast after each other
    244.     if (lastJumpTime + jumpRepeatTime > Time.time)
    245.         return;
    246.  
    247.     if (IsGrounded()) {
    248.         // Jump
    249.         // - Only when pressing the button down
    250.         // - With a timeout so you can press the button slightly before landing    
    251.         if (canJump  Time.time < lastJumpButtonTime + jumpTimeout) {
    252.             verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
    253.             SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    254.         }
    255.     }
    256. }
    257.  
    258.  
    259. function ApplyGravity ()
    260. {
    261.     if (isControllable) // don't move player at all if not controllable.
    262.     {
    263.         // Apply gravity
    264.         var jumpButton = Input.GetButton("Jump");
    265.        
    266.        
    267.         // When we reach the apex of the jump we send out a message
    268.         if (jumping  !jumpingReachedApex  verticalSpeed <= 0.0)
    269.         {
    270.             jumpingReachedApex = true;
    271.             SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
    272.         }
    273.    
    274.         if (IsGrounded ())
    275.             verticalSpeed = 0.0;
    276.         else
    277.             verticalSpeed -= gravity * Time.deltaTime;
    278.     }
    279. }
    280.  
    281. function CalculateJumpVerticalSpeed (targetJumpHeight : float)
    282. {
    283.     // From the jump height and gravity we deduce the upwards speed
    284.     // for the character to reach at the apex.
    285.     return Mathf.Sqrt(2 * targetJumpHeight * gravity);
    286. }
    287.  
    288. function DidJump ()
    289. {
    290.     jumping = true;
    291.     jumpingReachedApex = false;
    292.     lastJumpTime = Time.time;
    293.     lastJumpStartHeight = transform.position.y;
    294.     lastJumpButtonTime = -10;
    295.    
    296.     _characterState = CharacterState.Jumping;
    297. }
    298.  
    299. function Update() {
    300.    
    301.     if (!isControllable)
    302.     {
    303.         // kill all inputs if not controllable.
    304.         Input.ResetInputAxes();
    305.     }
    306.  
    307.     if (Input.GetButtonDown ("Jump"))
    308.     {
    309.         lastJumpButtonTime = Time.time;
    310.     }
    311.  
    312.     UpdateSmoothedMovementDirection();
    313.    
    314.     // Apply gravity
    315.     // - extra power jump modifies gravity
    316.     // - controlledDescent mode modifies gravity
    317.     ApplyGravity ();
    318.  
    319.     // Apply jumping logic
    320.     ApplyJumping ();
    321.    
    322.     // Calculate actual motion
    323.     var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0) + inAirVelocity;
    324.     movement *= Time.deltaTime;
    325.    
    326.     // Move the controller
    327.     var controller : CharacterController = GetComponent(CharacterController);
    328.     collisionFlags = controller.Move(movement);
    329.    
    330.     // ANIMATION sector
    331.     if(_animation) {
    332.         if(_characterState == CharacterState.Jumping)
    333.         {
    334.             if(!jumpingReachedApex) {
    335.                 _animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
    336.                 _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
    337.                 _animation.CrossFade(jumpPoseAnimation.name);
    338.             } else {
    339.                 _animation[jumpPoseAnimation.name].speed = -landAnimationSpeed;
    340.                 _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
    341.                 _animation.CrossFade(jumpPoseAnimation.name);              
    342.             }
    343.         }
    344.         else
    345.         {
    346.             if(controller.velocity.sqrMagnitude < 0.1) {
    347.                 _animation.CrossFade(idleAnimation.name);
    348.             }
    349.             else
    350.             {
    351.                 if(_characterState == CharacterState.Running) {
    352.                     _animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, runMaxAnimationSpeed);
    353.                     _animation.CrossFade(runAnimation.name);   
    354.                 }
    355.                 else if(_characterState == CharacterState.Trotting) {
    356.                     _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, trotMaxAnimationSpeed);
    357.                     _animation.CrossFade(walkAnimation.name);  
    358.                 }
    359.                 else if(_characterState == CharacterState.Walking) {
    360.                     _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, walkMaxAnimationSpeed);
    361.                     _animation.CrossFade(walkAnimation.name);  
    362.                 }
    363.                
    364.             }
    365.         }
    366.     }
    367.     // ANIMATION sector
    368.    
    369.     // Set rotation to the move direction
    370.     if (IsGrounded())
    371.     {
    372.        
    373.         transform.rotation = Quaternion.LookRotation(moveDirection);
    374.            
    375.     }  
    376.     else
    377.     {
    378.         var xzMove = movement;
    379.         xzMove.y = 0;
    380.         if (xzMove.sqrMagnitude > 0.001)
    381.         {
    382.             transform.rotation = Quaternion.LookRotation(xzMove);
    383.         }
    384.     }  
    385.    
    386.     // We are in jump mode but just became grounded
    387.     if (IsGrounded())
    388.     {
    389.         lastGroundedTime = Time.time;
    390.         inAirVelocity = Vector3.zero;
    391.         if (jumping)
    392.         {
    393.             jumping = false;
    394.             SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
    395.         }
    396.     }
    397. }
    398.  
    399. function OnControllerColliderHit (hit : ControllerColliderHit )
    400. {
    401. //  Debug.DrawRay(hit.point, hit.normal);
    402.     if (hit.moveDirection.y > 0.01)
    403.         return;
    404. }
    405.  
    406. function GetSpeed () {
    407.     return moveSpeed;
    408. }
    409.  
    410. function IsJumping () {
    411.     return jumping;
    412. }
    413.  
    414. function IsGrounded () {
    415.     return (collisionFlags  CollisionFlags.CollidedBelow) != 0;
    416. }
    417.  
    418. function GetDirection () {
    419.     return moveDirection;
    420. }
    421.  
    422. function IsMovingBackwards () {
    423.     return movingBack;
    424. }
    425.  
    426. function GetLockCameraTimer ()
    427. {
    428.     return lockCameraTimer;
    429. }
    430.  
    431. function IsMoving ()  : boolean
    432. {
    433.     // Original script
    434.     //return Mathf.Abs(Input.GetAxisRaw("Vertical")) + Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5;
    435.    
    436.     // For EasyJoystick
    437.     return Mathf.Abs(myJoy.JoystickAxis.x) + Mathf.Abs(myJoy.JoystickAxis.y) > 0.5;
    438. }
    439.  
    440. function HasJumpReachedApex ()
    441. {
    442.     return jumpingReachedApex;
    443. }
    444.  
    445. function IsGroundedWithTimeout ()
    446. {
    447.     return lastGroundedTime + groundedTimeout > Time.time;
    448. }
    449.  
    450. function Reset ()
    451. {
    452.     gameObject.tag = "Player";
    453. }
    454.  
    455.  
     
  16. darryl

    darryl

    Joined:
    Feb 19, 2013
    Posts:
    2
    why does the joystick disable when i switch scenes?
     
  17. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi darryl,

    I assume you mean when you load a new scenes ?

    When you load a new scene, the objects are replaced by the news. You have two solutions for your problem :

    - Create a new joustick in your second scene.
    or
    - Create a new script, and use the method DontDestroyOnLoad and attach this script to your joystick.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class KeepJoy : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         DontDestroyOnLoad(this);   
    9.     }
    10.    
    11. }
     
  18. darryl

    darryl

    Joined:
    Feb 19, 2013
    Posts:
    2
    i think i just figured it out. i didn't realize the easytouch gameobject was important for it to operate, so it was on different settings in my different scenes. really appreciate the quick response though!
     
  19. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Darryl;

    Oh sorry I did not think about that, EasyJoystick uses EasyTouch, so you must also use one of the technical for your EasyTouch gameobject.
     
  20. HH_Gorgon

    HH_Gorgon

    Joined:
    Nov 8, 2012
    Posts:
    8
    Does 2.5.1 work with Unity 3.5.6? If we purchase this asset for use with 3.5.6 and run into any issues will you still be able to provide support?
     
  21. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Ninerealms,

    EasyTouch works with Unity 3.5.X 4.X. Off course if you haves any issue you will have support !
     
  22. Thinice

    Thinice

    Joined:
    Jan 20, 2012
    Posts:
    35
    Hi,

    I just bought this, imported it and placed "Gizmos" and "Plugins" folders at the root of my project. Unity throws 75 errors. What's going on? Am I doing something wrong?

    I'm using UnityScript, Unity version is 4.0.1f2
     
  23. Thinice

    Thinice

    Joined:
    Jan 20, 2012
    Posts:
    35
    Ooops, nevermind, my fault! A few scripts were not moved correctly to the root folder. Everything is Ok now.
     
  24. ZINI-NGR

    ZINI-NGR

    Joined:
    Jan 28, 2013
    Posts:
    20
    Hello, I bought this now and test this. I think that is very good asset. But, there is thing, which wonder one kind,
    How can i joystick auto resize in each mobile resolution? (if resolution is small, i want joystick resize automatically)
     
  25. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi 45efdg,

    This feature is already done , and it will be public available in the next release :)

    Nicolas
     
  26. ZINI-NGR

    ZINI-NGR

    Joined:
    Jan 28, 2013
    Posts:
    20
    thanks, Nicolas. I am looking forward to next release update soon :) And... I have one more question.
    I'm making 3rd person game(TPS?). but when i use this asset, Character is always look front.
    when i move joystick to left...right....backward..... Character is moving but always look front.
    if i move joystick to left, i want my character is look at left and move to left too. How can i change this?
     
    Last edited: Feb 22, 2013
  27. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi 45efdg,

    You can download a example scene to do what you want : Here
     
  28. ZINI-NGR

    ZINI-NGR

    Joined:
    Jan 28, 2013
    Posts:
    20
    WOW! It's really COOL~!! Thank you very much for your Fantastic support :)
     
  29. Alessaint

    Alessaint

    Joined:
    Mar 21, 2011
    Posts:
    43
    Hi Nicolas,

    I've run into some problems while using Easy Touch when the game is paused (Time.timeScale = 0). If it's paused On_SimpleTap delegate is called only the first time I tap and then never again...

    Is possible that you use game time (paused) instead of the real time in your script to check for delays between taps or something like that?

    Other than that - your plugin is really great :)

    Ales
     
  30. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Alessaint,

    I don't use Time class for the tap, so I must look what happen when Time.timeScale =0.

    I circle back to you.
     
  31. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Nicolas,

    I have a problem with my swipes.I want to swipe objects away from the screen. Here is my script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TouchControls : MonoBehaviour
    6. {
    7.     private float speedX;
    8.     private float speedZ;
    9.     private float speedFactor = 0.05f;
    10.     private string swipeDir;
    11.    
    12.     private Vector3 pos;
    13.    
    14.     void Update ()
    15.     {
    16.         speedX = this.gameObject.transform.position.x;
    17.         speedX += speedFactor;
    18.         this.gameObject.transform.position = new Vector3(speedX, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
    19.     }
    20.    
    21.     void OnEnable()
    22.     {
    23.         EasyTouch.On_Swipe += HandleEasyTouchOn_Swipe;
    24.     }
    25.  
    26.     void OnDisable()
    27.     {
    28.         EasyTouch.On_Swipe -= HandleEasyTouchOn_Swipe;
    29.     }
    30.    
    31.     void OnDestroy()
    32.     {
    33.         EasyTouch.On_Swipe -= HandleEasyTouchOn_Swipe;
    34.     }
    35.    
    36.    
    37.     void HandleEasyTouchOn_Swipe (Gesture gesture)
    38.     {
    39.         if(gesture.swipe == EasyTouch.SwipeType.Up)
    40.         {
    41.             swipeDir = "up";   
    42.         }
    43.        
    44.         if(gesture.swipe == EasyTouch.SwipeType.Down)
    45.         {
    46.             swipeDir = "Down";
    47.         }
    48.        
    49.         switch(gesture.pickObject.name.ToString())
    50.         {
    51.             case "Banana(Clone)":   Banana(gesture.pickObject.gameObject);
    52.                                     break;
    53.            
    54.             case "Pickle(Clone)":   Pickle(gesture.pickObject.gameObject);
    55.                                     break;
    56.                
    57.             case "Pepper(Clone)":   Pepper(gesture.pickObject.gameObject);
    58.                                     break;
    59.         }
    60.        
    61.     }
    62.    
    63.        
    64.    
    65.    
    66.     void Banana(GameObject banana)
    67.     {
    68.         if(swipeDir == "Up")
    69.         {  
    70.             speedZ = banana.gameObject.transform.position.z;
    71.             speedZ += 0.05f;
    72.             banana.gameObject.transform.position = new Vector3(banana.gameObject.transform.position.x, banana.gameObject.transform.position.y, speedZ);
    73.         }
    74.        
    75.         if(swipeDir == "Down")
    76.         {
    77.             speedZ = banana.gameObject.transform.position.z;
    78.             speedZ -= 0.05f;
    79.             banana.gameObject.transform.position = new Vector3(banana.gameObject.transform.position.x, banana.gameObject.transform.position.y, speedZ);
    80.         }
    81.        
    82.         //pos = banana.transform.position;
    83.  
    84.     }
    85.    
    86.     void Pickle(GameObject pickle)
    87.     {
    88.         //pos = pickle.transform.position;
    89.  
    90.     }
    91.    
    92.     void Pepper(GameObject pepper)
    93.     {
    94.         //pos = pepper.transform.position;
    95.  
    96.     }
    97.    
    98. }
    99.  
    100.  
    The problem i'm having is when i want to swipe an object the gesture.pickobject remains null so iget a nullreference exception :(
     
  32. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi tripwire,

    When you swipe hover on object, you will receive a drag event, not a swipe. Try your script with HandleEasyTouchOn_Drag
     
  33. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Thx for your reply!
    Right but how do i know which waty the player swipes / drags then? Because there is no option like gesture.swipe == EasyTouch.SwipeType.Up
     
  34. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    When you receive the drag event, you a gesture class parameter with these information. Look at One finger example
     
  35. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Sorry i don't understand what you are saying now...
     
  36. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi tripwire

    Go to skype ! call me
     
  37. nilton_felicio

    nilton_felicio

    Joined:
    May 17, 2012
    Posts:
    66
    I'm having problems to use Easy Touch 2.5.
    Is there a tutorial that explains the more detailed usage?
     
  38. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Nilton_felicio,

    You have at your disposal all the examples that use all EasyTouch features.

    Or if you have a skype account, I can talk to you for more explainations. I know it isn't very easy if you nerver use a framework and event progamming


    Nicolas
     
    Last edited: Feb 25, 2013
  39. nilton_felicio

    nilton_felicio

    Joined:
    May 17, 2012
    Posts:
    66
    Actually I am not an expert programmer. The examples are great, the plugin demonstrates be efficient, Joystick is perfect and is already used fucional. But I am facing problems to use tap, double tap, swipe, twist, pinch ... in my game elements. I found no tutorial explains how to use these functions in my game objects. Could have actions on Easy Touch Playmaker? But again your product is excellent'm just having trouble knowing how to use it...
     
  40. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    do you do the little tutorial, that you can find in the documentation ?

    Nicolas
     
    Last edited: Feb 25, 2013
  41. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    For nilton_felicio

    You want to use EasyTouch with Playmaker ?
     
  42. nilton_felicio

    nilton_felicio

    Joined:
    May 17, 2012
    Posts:
    66
    Simple: I have a sprite in the game, as I click or drag this. What code in your package Easy Touch I drag for this sprite. If it was a photo twist and pinch?
    What code to use? I want to send Feedback after clicking for example ..... Sorry if this is simple and I'm making it hard to understand ... If you can help me, thank you for your attention and...
     
  43. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    For nilton

    There isn't drag and drop script, you must create script from scratch and suscribe to event that you need. It would be easier if I show you how to do , rather than give you a big speech.

    You don't have a skype account ?
     
  44. nilton_felicio

    nilton_felicio

    Joined:
    May 17, 2012
    Posts:
    66
    If possible it would be great to have EasyTouch with actions within the Playmaker. I sent my skype via PM. Several Addons for playnaker this link, EasyTouch could be there ...
     
    Last edited: Feb 26, 2013
  45. vinkim

    vinkim

    Joined:
    Dec 3, 2012
    Posts:
    2
    Hey, I was looking into this asset, I see that you can at least do a few things without almost any coding yourself. I'm not a seasoned C#/JS programmer, does it require a lot of code to make an object for exampel change color on a tap? Also, I saw your webdemo(the two about movement where it said nothing was coded except adding the scripts), would it be a lot of work to just make the camera move 90 degrees left/right in a first person camera depending on the swipe.
    Last question, do you have any API?

    Thanks!
     
  46. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi vinkim,

    EasyTouch manages for you all gesture recognition, and notifies you with events of current gesture on the touch screen.

    However, it remains your responsibility code corresponding to the action. For example, if you want to change the color of an object in a TAP gesture, you simply subscribe to the tap event, but the color change you must code it yourself with Unity frameWork.

    EasyTouch requires a minimum of knowledge in Unity scripting in order to achieve what you want to do whe you receive an event.

    When I said the just adding the script, it"s the action to be notified of touches events.


    Nicolas
     
  47. vinkim

    vinkim

    Joined:
    Dec 3, 2012
    Posts:
    2
    Sounds good :) Thanks a bunch for the fast reply!

    Edit: I bought it shortly after, and after struggling for a few days with trying out on my own etc, I gotta say...it's awesome! I already implemented a few things like Joystick, tap etc, and it's working like a charm! I'll rate it with a full score!
     
    Last edited: Mar 1, 2013
  48. larryapple

    larryapple

    Joined:
    Mar 1, 2013
    Posts:
    7
    Hello, I bought EasyTouch yesterday, created a new project and imported the plugin and examples. Some of the examples run, but not the one I want most, which is the single finger drag. None of the single finger examples do anything in Mac/PC mode. They work when built on IOS, but I have not been able to get it to work on my assets in my game, on either Mac or IOS. Some of the other examples work with the mouse and fake 2nd finger, but seem somewhat flaky with my Mac trackpad.

    I am running on Mac OS Mountain Lion and Unity 4 Pro.

    Please help.

    Edit: Apparently the problems are with pickObject - Your documentation about that subject is lacking. Once I set the EasyTouch pickable layers to "Everything", it started working.
     
    Last edited: Mar 3, 2013
  49. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Nicolas,

    Here i am again with a question :) i'm having some problems with touch not working after playing a video. I have an IOS App which has video's in it. And when i tap a video it goes to the native video player on my iPad and the video starts playing. Then when i tap on done the ipad switches back to the app. But then the touch isn't working anymore :( is this a Unity3D problem or a EasyTouch bug?

    Thx in advance for your help!
     
    Last edited: Mar 3, 2013
  50. ShinyTaco

    ShinyTaco

    Joined:
    Sep 4, 2012
    Posts:
    70
    Hi Nicolas,

    I purchased EasyTouch about a week or two ago and think it's a great product. Thank you.

    However, I have come across something strange. Maybe there is a problem with my code somewhere, or not.

    I have simply attached a 3d sound, which is my level music to a game object. However, for some reason when I walk and run my character around the screen using EasyTouch it speeds up the music. If I run forward it speeds up the music very, very fast, and if I run back away from it, it slows it down, very slow.

    It does not do this if the music is 2d.

    I would like to have this music 3d for my game.

    Any ideas what could be wrong?

    Thank you.