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 rhose87 · Nov 11, 2011 at 09:17 AM · touchscreenorbitmouseorbit

touchscreen and mouse orbit

I have a HP2310 touchscreen and an orbit script. When i use the mouse works perfect, but when i use the finger it doesn't.

 function LateUpdate () {
     x += Input.GetAxis("Mouse X") * xSpeed *0.02; //x rotation
 gameObject.Find("testMouse").guiText.text = Input.GetAxis("Mouse X").ToString();
     y -= Input.GetAxis("Mouse Y") * ySpeed *0.02;  //y rotation
     gameObject.Find("testMouse2").guiText.text = Input.GetAxis("MouseY").ToString();
     y = ClampAngle(y, yMinLimit, yMaxLimit);
     var rotation = Quaternion.Euler(y, x, 0);
     var position = rotation * Vector3(0.0, 0.0, -distance)+ target.position;
       transform.rotation = rotation;
     transform.position = position; 
 }

I uses 2 gui text to print the mouse position when i run the project in standalone mode. The results : when using the mouse it prints values beetween -1 and 1 but with finger nothing is printed.

I've notice that the touch reacts to the OnMouseEnter event. How can i modify this to check is mouse entered my object?

Ideas ?

Comment
Add comment · Show 6
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 cj_coimbra · Nov 11, 2011 at 11:00 AM 0
Share

You mean if the touch is over the object? You might need to use Raycasting.

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

avatar image rhose87 · Nov 11, 2011 at 11:11 AM 0
Share

yes, touch over the object.

avatar image cj_coimbra · Nov 11, 2011 at 11:16 AM 0
Share

Let met see if I fully understood what you need: you want to touch than drag the touch and when you reach an object during this drag you want to do something?

avatar image rhose87 · Nov 11, 2011 at 11:18 AM 0
Share

i want the object to rotate like it does on mouseOrbit script, but using the touch.

avatar image cj_coimbra · Nov 11, 2011 at 11:24 AM 0
Share

You want to same camera effect that $$anonymous$$ouseOrbit does with mouse, but using touch, right? Well it should work right away. I´ve used it a while ago and no modification were needed, I just changed it a bit to get it more smooth to the touch. I´ll search the code I used here and send it to you as soon as I find it...

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by rhose87 · Nov 14, 2011 at 01:42 PM

I solved my problem with the folowing code :

function Update(){
var curentX = Input.mousePosition.x;
var differenceX = curentX-startX;   
if(differenceX>0)
   target.transform.Rotate(0.0, -10*xSpeed*Time.deltaTime*0.1, 0.0,Space.World);
if(differenceX<0)
   target.transform.Rotate(0.0, 10*xSpeed*Time.deltaTime*0.1, 0.0,Space.World);     
startX = curentX;
differenceX = 0;    
}
function Start(){
     startX = Input.mousePosition.x;    
}

Comment
Add comment · Show 2 · Share
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 illfusebox · Jan 16, 2012 at 01:36 PM 0
Share

rhose87, i have an error in this code please help me me and you have the same question.. i want to try your code.. i have an error "unknown identifier startX,target,xSpeed,target,xSpeed" thanks for your help

avatar image rhose87 · Jan 18, 2012 at 10:35 AM 0
Share

declare them as variables. target is a game object.

 var startx; //etc
avatar image
2

Answer by yusufulutas · Nov 12, 2011 at 11:37 AM

TouchPhase.Moved and Touch.deltaPosition

I think this will work if you use them.

Example of use:

Touch finger = Input.GetTouch(0);// 0 is first finger

finger.phase == TouchPhase.Moved;

finger.deltaPosition;// travels the path calculates the finger on the screen.

I'm sorry for my English is bad.

Comment
Add comment · Show 4 · Share
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 rhose87 · Nov 14, 2011 at 01:40 PM 0
Share

didn't work.

avatar image jahroy · Nov 17, 2011 at 05:49 PM 0
Share

This is the correct approach.

The OP is trying to use mouse code for touch input.

He solved his specific issue with a workaround that will work now, but cause issues later if he tries to process more touch input (in my opinion).

avatar image Redbeef · Nov 04, 2013 at 02:29 AM 0
Share

Hi @jahroy, @yusufulutas, can you guys please clarify the getTouch approach? How do I edit the existing code?\ Thanks, Garry

avatar image jahroy · Nov 04, 2013 at 03:25 AM 0
Share

@redbeef - Here is the documentation for Input.GetTouch(), which returns a Touch object:

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html

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

7 People are following this question.

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

Related Questions

Mouse orbit on a touchscreen 2 Answers

Third Person Controller Falls Through Terrain Upon Adding Mouse Orbit 1 Answer

Rotate camera to object on sphere 1 Answer

Why Does This C# Code Do Nothing? 2 Answers

How do I combine Orbiting with mouse drag and with a button click? 0 Answers


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