Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by richardzzzarnold · Oct 28, 2012 at 03:08 PM · guitouchlerpoffsetmouseorbit

Mouse slingshot to touch control problem

I have a beautiful script adapted from a sidescrollling GUI script that lets me make a FPS slingshot GUI which has rotation control and adjusts tension according to how far you pull the finger away. It works beautifully on the computer but on touchscreen I have the much documented (Touch)MouseOrbit problem with some problem ( that I cant quite put my finger on) between the last finger touch and the new finger touch. A previous answerer suggested that I should look at .: .......TouchPhase.Began....... Then move it only in TouchPhase.Moved or Stationary with Quaternion.Lerp(...)

but i cannot think hot to implement it.... hope someone can help... here is my script....:

 #pragma strict
 var loadedobject : GameObject;
 var barHeight : int = 32;
 var TargetBack : GUIStyle;
  var projectile : Rigidbody;
 var spacer : int = 8;
 var catapault : GameObject;
 var tiles : Tile[]; // home-made class. see the end of script.
 var springSpeed : float = 5.0; 
 var throwSpeed : float = 8.0;
 var strengthx : float;
 var strengthy : float;
 var strength : float;
 var ThrowAngle : float;
 var loaded : boolean;
 var tension : float;
 var sling : GameObject;
 var spawnpoint : GameObject;
 var tester : GUIStyle;
 
 var tileSize : float;
 private var screenWidth : int = Screen.width;
 private var screenHeight : int = Screen.height;
 private var slidePosition : Vector3;
 private var maxSlidePosition : Vector3;
 private var oldMousePosition : Vector3;
 private var throwPosition : Vector3;
 
 
 function Start () {
     // in a real senario maybe this is dynamically created from a database. for now, here are some blanks.
     tiles = [new Tile()];
     oldMousePosition = Input.mousePosition;
    
 
 
     
 
     
 }
 function Update () {
     catapault.transform.rotation.x=0;
     catapault.transform.rotation.z=0;
     if (!Input.anyKey) {
       
                slidePosition = Vector2.Lerp(slidePosition, Vector2((Screen.width/2)-tileSize/2,Screen.height/1.5), Time.deltaTime * springSpeed);
             oldMousePosition = Input.mousePosition;
             
     }
 
 
 
     if((Input.GetMouseButton(0))&&(new Rect(Screen.width/3,0,Screen.width/3,Screen.height/2).Contains(Input.mousePosition)))
     
          {
         slidePosition.x += Input.mousePosition.x - oldMousePosition.x;
         slidePosition.y += (Input.mousePosition.y - oldMousePosition.y)*-1;
         oldMousePosition = Input.mousePosition;
        }
     
     
     else if((Input.GetMouseButtonUp(0))&&(new Rect(0,0,Screen.width,Screen.height/3).Contains(Input.mousePosition))){
         Missile();
 slidePosition = Vector2.Lerp(slidePosition, Vector2((Screen.width/2)-tileSize/2,Screen.height/1.5), Time.deltaTime * springSpeed);
         
         
         
         
         }
         
     if(slidePosition.x<Screen.width/2-tileSize/2){
     strengthx = Screen.width/2-slidePosition.x-tileSize/2;
     ThrowAngle=strengthx/strengthy*-1;}
     else {
         strengthx = slidePosition.x-Screen.width/2+tileSize/2;
         ThrowAngle=strengthx/strengthy;}
     if(slidePosition.y<Screen.height/2){
         strengthy=Screen.height/2-slidePosition.y;
         ;}
     
     else{
         strengthy=slidePosition.y-Screen.height/2;
         }
     strength=Mathf.Sqrt((strengthx*strengthx)+(strengthy*strengthy));
     catapault.transform.localEulerAngles.y=ThrowAngle*-45;
     tension = strength/250;
     
     tileSize = Screen.width/10;
     if(strength>0){
     sling.transform.localScale=Vector3(1,1,tension);    
     
     }
 }
 function OnGUI () {
     screenWidth = Screen.width;
     screenHeight = Screen.height;
    
 
     var xMax : int = Mathf.CeilToInt(tiles.length/3.0f);
     maxSlidePosition.x = -spacer*(xMax+1)-tileSize*(xMax)+screenWidth;
 
     for (var i=0; i<tiles.length; i++){
        var position : float = i+1;
        var xGridPosition : int = Mathf.CeilToInt(position/3.0f);
        var yGridPosition : int = Mathf.CeilToInt(position/3.0f);
        var rect : Rect = new Rect(spacer*xGridPosition+tileSize*(xGridPosition-1)+slidePosition.x, spacer*xGridPosition+tileSize*(xGridPosition-1)+slidePosition.y, tileSize, tileSize);
        var tile : Tile = tiles[i];
        GUI.Box(rect, tile.name);
     }
     GUI.Box(Rect(Screen.width/3, Screen.height/1.5,Screen.width/3, Screen.height/2),"", TargetBack);
     
     
 }
 
 function Missile(){
     
     var clone : Rigidbody;
 
 clone = Instantiate(projectile, spawnpoint.transform.position, catapault.transform.rotation);
 clone.velocity = catapault.transform.TransformDirection (Vector3.forward*strength*.1);
 loadedobject.SetActiveRecursively(false);
 yield WaitForSeconds(1);
 loadedobject.SetActiveRecursively(true);
 }
 
 
 
 
 class Tile{
     var name : String = "indigo button";
     var texture : Texture2D;
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Oct 28, 2012 at 03:43 PM 0
Share

by no means easy. this info may help

http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html

Do you realise you're not actually using Touch on the code you pasted in? You won't be able to make it with the others

you'll need to master this Documentation/Documentation/ScriptReference/Touch.html

"can't quite put my finger on" Funny :)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Windows 7 touch not working correctly in WebGL! 1 Answer

GUI objects jitter when following "lerped" Gameobject [SOLVED] 1 Answer

Drag and Drop button on Mobile (Messenger style) 0 Answers

Why does the time in Vector3.Lerp effect my position? 1 Answer

Touch Input on Sprites 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges