• 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 3kWikiGames · Dec 18, 2018 at 11:21 PM · movement3dtouchcamera rotatefollow

Player not following touch after camera is rotated?

So after I slant the camera slightly so in my game it seems that the touch is completely off, not following their touch and going completely random directions. This doesn't happen when it is centered rotationally at 0 and flush with the wall, but this also does not allow me to view my 3d objects the way I want, showing them as flat squares instead of a table and chair. Any way to fix this? Below ive included my code for moving and a photograph.alt text

 //Gathering resources
 using UnityEngine;
 using System.Collections;
 
 //The Move class decleration
 public class Move : MonoBehaviour
 {
     //How quickly the player follows the mouse
     public float Speed = 10f;
     public float maxSpeed = 50f;
     public float distance = .1f;
     private float moveSpeed = 10f;
 
     public GameObject flashlight;
 
     //Called every frame
     void Update()
     {
         if (Input.touchCount > 0 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(0).phase == TouchPhase.Stationary))
         {
             Speed = 10f;
             moveSpeed = 10f;
             maxSpeed = 50f;
         }
         else
         {
             Speed = 0;
             moveSpeed = 0;
             maxSpeed = 0;
         }
 
         if (Input.mousePresent)
         {
             movePlayer();
             turnFlashlight();
         }
     }
 
     private void movePlayer()
     {
         //Converting mouse position into Vector3
         Vector3 Target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         //Fixing Z-Axis
         Target.z = transform.position.z;
         Speed = (moveSpeed + (moveSpeed * (Vector3.Distance(Target, transform.position))));
         if (Speed > maxSpeed)
         {
             Speed = maxSpeed;
         }
         if (Vector2.Distance(Target, transform.position) <= 0.1f)
         {
             Speed = 0;
         }
 
         //Actually move the player towards the mouse.
         transform.position = Vector3.MoveTowards(transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
 
     }
 
     private void turnFlashlight()
     {
         Vector3 Target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         Vector3 Click = new Vector3(Target.x, Target.y, 0.0f);
 
         if (Input.GetMouseButton(0) & !CharacterSettings.paused)
         {
             flashlight.transform.LookAt(Click);
         }
         
     }
 }


screenshot-240.png (376.6 kB)
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

184 People are following this question.

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

Related Questions

3D RTS camera 3 Answers

Vector3 MoveTowards character flying up when told to follow,Vector3 MoveTowards object flying up when I press play 0 Answers

How to move character horizontally with Touch, while player always runs forward? 2 Answers

Player movement for iOS? 1 Answer

3d Space Movement 1 Answer


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