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 /
avatar image
1
Question by brandoncluff · Aug 17, 2018 at 04:52 PM · rotationmovementmecanimjoysticktranslate

Left Joystick Translation Depending on Facing Direction

I'm hitting a wall on this really simple problem... I know there has to be a simple solution, but I'm not exactly sure what it is. I'm prototyping for a game jam -- my game is a top down, 3D twin sticks style game. The right stick rotates the player and the left stick controls the movement. The movement is done via animations in Mecanim -- I have forward/backward/strafing setup and blended.


My problem is right now it moves like Resident Evil -- "up" on the joystick drives the character forward no matter what direction she is facing. I need to translate "up" on the joystick to be relative to the world -- not the player (ie: if facing right, "up" should make her strafe left). What am I trying to find? I'm pretty sure there's some built it translation that I need to call...


I'm using Unity and am sending Horizontal and Vertical values between -1 and 1 to Mecanim. I need to translate these values based on character rotation so "up" moves the character toward the top of the screen based on it's original rotation.


alt text

img4.jpg (185.7 kB)
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 brandoncluff · Aug 17, 2018 at 11:59 PM 0
Share

Working code:

 moveDirection = new Vector3(Input.GetAxis("Joystick Horizontal"), 0f, Input.GetAxis("Joystick Vertical"));
 moveDirection = gameObject.transform.InverseTransformDirection(moveDirection);
 moveHorizontal = $$anonymous$$athf.Clamp(moveDirection.x, -1, 1);
 moveVertical = $$anonymous$$athf.Clamp(moveDirection.z, -1, 1);

Thanks @eres !

1 Reply

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

Answer by eses · Aug 17, 2018 at 05:43 PM

Hi @brandoncluff

You need to do space conversion for your direction vector.

Unity has built in methods in Vector classes called (several), in this case:

 var h = Input.GetAxis("Horizontal");
 var v = Input.GetAxis("Vertical");
 ctrlVec = new Vector3(h,0,v);
 relVec = body.InverseTransformDirection(ctrlVec);



Now when you press L stick up, (0,0,1), vector direction will be rotated relative to characters forward, and value will be (-1,0,0), which is left in character local space, which can drive possibly your animation clips.

Comment
Add comment · Show 3 · 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 brandoncluff · Aug 17, 2018 at 06:58 PM 0
Share

Thanks! I'll give this a shot. If it works, I'll accept your answer and post the code to help anyone else having similar issues!

avatar image eses brandoncluff · Aug 17, 2018 at 07:27 PM 0
Share

I tested it - at least it works as I undestood it :)

avatar image brandoncluff eses · Aug 17, 2018 at 11:57 PM 0
Share

Totally works!

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

228 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 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

Rotate object to joystick and position direction 0 Answers

How to make player go forward when he is rotated? 0 Answers

Mathf.Clamp not clamping properly 0 Answers

How to translate an object in an unknown angle ? 1 Answer

How do i rotate an object towards joystick cursor position? 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