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 Tageos · Dec 24, 2014 at 12:24 PM · 2dtouch controlsmultitouch

Go from mouse to multitouch?

Hey I am making a game were you are controlling 2 turrets. I have asigned a script to both of the turrets that makes them follow the mouse like this:

alt text

This is the script:

 #pragma strict
 
 function Start () {
 
 }
 
  var mouse_pos : Vector3;
  var target : Transform; //Assign to the object you want to rotate
  var object_pos : Vector3;
  var angle : float=180;
  
  function Update ()
  {
      mouse_pos = Input.mousePosition;
      mouse_pos.z = 5.23; //The distance between the camera and object
      object_pos = Camera.main.WorldToScreenPoint(target.position);
      mouse_pos.x = mouse_pos.x - object_pos.x;
      mouse_pos.y = mouse_pos.y - object_pos.y;
      angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
      transform.rotation = Quaternion.Euler(Vector3(0, 0, angle));
      };


What i want to do is making them follow your touch seperatly like this:

alt text

Imagine the screen is split in half were the left side controlls the movement of the left turret and the right side controls the right turret.

They only move when you touch the screen, when you move your fingers away they should stay in the same position as they where left. I would also like to implement an angle intervall were the turrets can move between, so that the pipe dont touch their "stand", maybe between 20 and 160 degrees.

I realize that these things are not easy tasks, but can you try to give me some input on how and where to start? Any thought on how to do all this?

untitled2.png (3.7 kB)
untitled.png (4.3 kB)
Comment
Add comment · Show 2
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 Josh Naylor ♦♦ · Dec 24, 2014 at 12:28 PM 0
Share

Software development is all about breaking down problems to simpler steps. Think about how your problem can be broken down. - So you have them both rotating to the 1st touch position. - Split the screen in half and take the touch position from the left side and apply it to "left turret" only. same thing with the right. - then add when nothing is being touched keep the angle the last saved angle - add a range that the angle can be so it stays within the bounds.

Implementing step by step helps you solve problems quicker and if something breaks you know which step it was.

avatar image Tageos · Dec 28, 2014 at 12:10 AM 0
Share

Being somewhat of a newbie in the area of coding makes me appretiate these kind of comments, thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Dec 24, 2014 at 12:42 PM

Look into Input.touches. Find active touches, check which are on left side of the screen and which on the right. Use one for one turret, other for the other. Just as you use mouse input.

Comment
Add comment · Show 1 · 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 Tageos · Dec 28, 2014 at 12:11 AM 0
Share

Thanks for the tip! I am looking into input.touches as we speak.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help With Multitouch in 2D Windows Store apps 0 Answers

Problem in multi touch 0 Answers

Can't move and fire at the same time! 0 Answers

* SOLVED * Convert Input.GetAxis("Horizontal") to Touch Drag with Width Control 1 Answer

How to press 2 touch buttons at the same time unity 2d 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