Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Feb 17, 2016 at 05:27 AM by Hybrid-Dragon for the following reason:

Updated question to better describe needs/intentions in a new query.

avatar image
0
Question by Hybrid-Dragon · Jan 05, 2016 at 11:17 AM · movementmobilecharactercontrollerraycastingcharacter controller

Moving a character with touch controls relative to target?

16-02-2016

I have since reworked my controls to raycast on to the scene and the player moves towards that. This is still not my preferred method of movement, but I will be closing this question to link to a more descriptive question that explains better my intentions or needs. Thank you for the support. http://answers.unity3d.com/questions/1141246/how-can-i-get-vector-coordinates-from-a-raycast-re.html

~hy


Hello,
I am building a game where the camera is at a fixed position, rotation, etc. from a character. The camera is simply given a position offset from the character object. I have built controls to move this character based on the screen position of an input. This began to slowly fall apart as I have been unable to come up with a way to arbitrarily modify the origin of the movement.
I need a way to either:
-move the character relative to the centre of the screen
-move the character relative to its current position

At the moment it:
-moves relative to 0-1 scale screen coordinates (bottom-left is 0,0; top-right is 1,1)
-will only move left and downwards normally (the inverse of the screen's y-coordinate)

If a code sample is needed, here is the section of trouble (C#):

 public float walk = 12f;
     void Update(){
         if( (INPUT CONDITIONS) ){
             #if (UNITY_EDITOR || UNITY_STANDALONE)
             mdown = Camera.main.ScreenPointToRay(Input.mousePosition);
             #elif (UNITY_ANDROID || UNITY_IPHONE)
             mdown = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
             #endif
             RaycastHit mpointhit;
             
             if(Physics.Raycast(mdown, out mpointhit)){
                 mpoint.x = mpointhit.point.x;
                 mpoint.z = mpointhit.point.z;
                 move = new Vector3(mpoint.x, 0, mpoint.z);
                 move *= walk;
             }
         }
         user.transform.position += move*Time.deltaTime;
 }

I have taken out sections of comments and attempts to "reposition" the origin of movement, which included using Camera.main.pixelRect.center.
Thank you

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

  • Sort: 

Follow this Question

Answers Answers and Comments

44 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

Related Questions

First person movement with character controller does not detect ground properly 0 Answers

Problem with the Character Controller on the Y-Axis,Character Controller drifting in the Y Axis 0 Answers

Jump logic issues 0 Answers

CharacterController.Move with slow animals - they do not move 1 Answer

Help converting a character controller script to rigidbody 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