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 Zartis · Jun 05, 2012 at 02:28 PM · positionplayer movementtouchscreenrelative

Moving player relative to anywhere of the screen you are touching on

Hi I am trying to make a movement controls that is based on Flying hamster the game. In which there is an option to choose which controls to use. (In this situation, it's the relative control by touching anywhere on the screen to move the player). Here's the link to a video on Flying Hamster, [http://www.youtube.com/watch?v=FPok9pNY0wY][1]


I am trying to add in touch Controls 1. And I need it to be based on 3d instead of 2d. I had already coded some of the component but what I get is a working code but not what I had expected. (for example, instead of being able to control anywhere on the screen, I am limited to bottom centre of the screen as it will reach the limit of the screen if i press anywhere else)

 > /******Ipad 3rd Controls******/     
 > if(PlayerControlsState.ctrlState == PlayerControlsState.ctrlState.IpadThree)
 > {                  
 > if (!dashOn) 
 > {
 >  Debug.Log("pos" + pos +"position" + tr.localPosition);             
 > if(Input.GetMouseButtonDown(0))             
 > {                
 >  StartPosition(); //track the curr pos of mouse        
 > } 
 > if (Input.GetMouseButton(0)) 
 > { var touchEndPos : Vector2 = Vector2(Input.mousePosition.x / Screen.width,   
 > Input.mousePosition.y / Screen.height); 
 >         var touchDiff : Vector2 = touchEndPos - touchStartPos;
 >         var touchDist : float = touchDiff.magnitude;
 >         var startEnd : Vector2 = touchStartPos - Vector2(tr.localPosition.x,
 >                                                            tr.localPosition.y);
 >         Debug.Log(startEnd);
 >     if (touchDist > 0.01)
 >     { 
 >      if (touchDiff.x > 1)
 >         {pos.x *= -2; }
 >        else 
 >         {pos.x *= 2;}
 >      if (touchDiff.y > 1)
 >         {pos.y *= -2;} 
 >      else 
 >         {pos.y *= 2;}
 >     //pos *= 2;
 >     } //Debug.Log("touch distance :" + touchDist);
 >         touchEndPos.x *= tempScale.x;
 >         touchEndPos.y *= (tempScale.x + 10);//tempScale.y;
 >         touchEndPos.x += minPosClamp.x;
 >         touchEndPos.y += minPosClamp.y; 
 >         touchEndPos.x *= 1.2;
 >         touchEndPos.y *= 0.32;
 > //Debug.Log("End Pos :" + touchEndPos + "Pos :" + pos);
 >     tr.localPosition = Vector3.MoveTowards(tr.localPosition, pos, deltaSpeed);
 >     tr.localPosition = ClampPlayerPos(tr.localPosition,minPosClamp, maxPosClamp);     
 >   }
 > }
 >}

Sorry if it's long, this is my second time using UnityAnswer and first time using the snippet [1]: http://www.youtube.com/watch?v=FPok9pNY0wY

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 Zartis · Jun 06, 2012 at 04:13 AM 0
Share

Ok i manage to add the relative touch based on Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved and Input.touchCount from reading this http://unity3d.com/support/documentation/ScriptReference/Input.GetTouch.html

Now i just need to figure out if there is a better way to simulate the same result using mouse ins$$anonymous$$d

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make basic touch screen controls 1 Answer

Position set way off / Different coordinate system problem 0 Answers

need rotate when change position relative to char 1 Answer

Comparing to a relative position. 1 Answer

Is it possible to position a GameObject as relative to a GUI? 2 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