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 infinitypbr · Feb 06, 2013 at 03:24 AM · transformaxistransforms

How to make a character move on Local axis?

The code below is simplified, but works perfectly when the character is facing the right direction. But when they turn, they move on the global scale, not the local. They are not a child of any other object, so localPosition is the same result.

I can't seem to figure out how to make the playerObject transform on the local axis. Is there a way?

         moveX = currentTouchX - joystickCenterX;
         moveY = currentTouchY - joystickCenterY;

         playerObject.transform.position.z -= ((moveX * 100) * Time.deltaTime);
         playerObject.transform.position.x += ((moveY * 100) * Time.deltaTime);



OR ----

Is there a way to get the Local x/y touch of the control wheel? The wheel looks like this, with "North" up and South down etc:

alt text

I was thinking a good alternative would be that as the character rotates, the wheel rotates as a compass. However, I could not figure out how to make the code below register where the on the wheel (localPosition) the touch was. Any one know how to do that? (This code uses mouse, for testing).

 var screenPos2e = Input.mousePosition;
         var worldPos2e = guiCamera.ScreenToWorldPoint(screenPos2e);
         currentTouchX = worldPos2e.z;
         currentTouchY = worldPos2e.y;
         currentTouchZ = worldPos2e.z;
         var centere = Vector2(joystickCenterX, joystickCenterY);
         var currente = Vector2(currentTouchX, currentTouchY);  //<--- This!  How to make this the local x/y of the wheel?




screen shot 2013-02-05 at 7.36.41 pm.png (75.9 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by infinitypbr · Feb 06, 2013 at 05:54 AM

My programmer brother was kind enough to help me out (even though he was working on programming stuff all day!).

The solution looks like this:

         var playerAngle = Mathf.Deg2Rad * (360 - playerObject.transform.eulerAngles.y);
         var x2 = (moveX * Mathf.Cos(playerAngle)) - (moveZ *  Mathf.Sin(playerAngle));
         var z2 = (moveX * Mathf.Sin(playerAngle)) + (moveZ *  Mathf.Cos(playerAngle));
         
         playerObject.transform.position.z += ((z2 * 100) * Time.deltaTime);
         playerObject.transform.position.x += ((x2 * 100) * Time.deltaTime);
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

9 People are following this question.

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

Related Questions

Defining specific controls for rotation. 0 Answers

Need to change direction of transform? 2 Answers

Change position of camera on scene load? 1 Answer

How to change from Y axis to Z axis, transform.LookAt 1 Answer

Find a Position on the Axis of a GameObject 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