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 lvl9hero · Jun 24, 2014 at 04:17 AM · cameratouchplayer movementfollowpoint

player following touch position

omg how hard can it be to make a player object follow your finger's touch input? spent the past 5 hours googling it and looking on here Answers but others ask and still no one gives a solid solution...

I have a scene setup, camera is following the player object from a standard third-person view, tilted down towards the floor/player at a certain degree, following the player. I want to now move the player to anywhere I touch on the screen, move to wherever in the level and follow my finger if I continuously drag around the scene.. There is a ground plane. So the touch input coordinates I'm guessing will be a 2d coordinate (point on a screen), but the player object has to move left, right, forwards, backwards in 3d, most likely in the z-axis.

Refer to my previous question posted, with my existing code that does not work... http://answers.unity3d.com/questions/730252/moving-player-to-mouse-click-falling-through-scene.html The answer attempt provided didn't work, debug log was spitting out errors because I was trying to convert the answer attempt from C# to JS but I guess I did it all wrong too.

I read up everything from the Ray. api and how it draws a ray from wherever you touch on the screen to the scene but I'm not a programmer so I might have an idea how to get it to work but I'm struggling with actually getting the code to work.

I thought this was pretty common and a standard input method for controlling a player in a game... why is it so hard to find a solid answer anywhere? Please someone help a.s.a.p... so hard to move on with the project without having even the basic core element of the game figured out...

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 SteelArrow21 · Jun 24, 2014 at 07:31 PM 0
Share

Quick question, what type of camera are you using?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jun 24, 2014 at 04:29 AM

This issue is "hard" because different setups and different mechanics require different code. IMHO, the best solution to this specific problem is to use Unity's mathematical Plane class, and use the Plane.Raycast(). You can raycast against the ground plane (and you should if it is not flat), but the results will be off a bit because the the geometry. Here is a sample script using the mouse. I leave converting it to touch to you:

 #pragma strict
 
 var speed = 4.0;
 
 function Update() {
     var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     var plane = new Plane(Vector3.up, transform.position);
     var dist : float;
     if (plane.Raycast(ray, dist)) {
         transform.position = Vector3.MoveTowards(transform.position, ray.GetPoint(dist), speed * Time.deltaTime);
     }
 }
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 lvl9hero · Jun 24, 2014 at 07:27 PM 0
Share

thhank you very very, very much, that's a perfect jumping off point I could work with.

avatar image Maribe1 · Aug 18, 2014 at 05:35 PM 0
Share

A BIG BIG THAN$$anonymous$$ YOU FOR THIS !!!!!!!! but there's something wrong my charater collide all of my gameobject why?

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

how make this script follow a target. 1 Answer

Rotate camera smooth on touch 0 Answers

Camera relative rigidbody third person player movement 1 Answer

Moving Camera With 2 Players 3 Answers

Touch not working if camera is moved 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