Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Wested_Crean · Jul 10, 2015 at 07:25 AM · raycastpositiontouch

Teleporting player to touch position and ray problem

I have a huge problem which I couldn't resolve for days. When player is tapping the screen 2 times, I want to check if touch hit one of two buttons (left/right arrow), and if not, teleport the player to Input.GetTouch(0).position x and y. I'm a beginner and I also need someone to explain rays and raycasting to me.

I hope for fast response so I can get back to work fast too :(

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by GiyomuGames · Jul 10, 2015 at 08:10 AM

To teleport the player you just need to do: transform.position = Input.GetTouch(0).position

For Raycasting: https://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting

But if you are asking these questions I believe you should go through some of Unity's tutorials first. https://unity3d.com/learn/tutorials/modules

Comment
Add comment · 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
1

Answer by Wested_Crean · Jul 14, 2015 at 02:01 PM

So, I've found the solution on my own.

First, I've created a function that handles the teleportation.

 void Teleport ()
     {
         Vector3 teleTouch = Camera.main.ScreenToWorldPoint(new Vector3 ( Input.GetTouch (0).position.x , Input.GetTouch(0).position.y, 10) );
         transform.position = teleTouch;
     }

then, in FixedUpdate I've added

 if(myBody.velocity.x == 0 && Input.GetTouch (0).phase == TouchPhase.Began)
             Teleport();

So function is called only if the player isn't moving (normally he moves by using left/right button)

Works perfectly and I've learned something.

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 Nithinsvs · Jun 11, 2018 at 06:30 AM 0
Share

And what if I need to control (move) player without teleporting on touch ??

avatar image
0

Answer by Nithinsvs · Jun 11, 2018 at 06:32 AM

And what if i need to control player without teleporting on touch ?? @Wested_Crean

Comment
Add comment · 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

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

Getting raycast to fire at touch position but only when second finger is on screen 0 Answers

How do you Draw a Line Using your Finger's Position on Android 3 Answers

Check if player object is right above this object 1 Answer

Input Touch.position 'inverted' relative to screen? 1 Answer

solution to detect multi- finger touch position 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