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 Triqy · Aug 29, 2013 at 01:32 AM · animationmobilemecanimcontrolsjoysticks

How do I controll a Character using the Mecanim Animator with Player Joysticks?

So i made a character and followed the tutorial at https://www.youtube.com/watch?v=Xx21y9eJq1U

That like is a tutorial on how to integrate the Mecanim Animator with your characters with your keyboard.

So my question is how do you integrate is this with the Player Relative Joysticks?

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 Triqy · Aug 29, 2013 at 10:31 PM 0
Share

got to bump this up!

2 Replies

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

Answer by meat5000 · Aug 31, 2013 at 12:07 AM

The keyboard handles axes the same as anything else.

Look at AngryBots tutorial project at the FreeMovementMotor and PlayerMoveController scripts.

They contain things like:

 #if UNITY_IPHONE || UNITY_ANDROID
         if (joystickPrefab) {
             // Create left joystick
             var joystickLeftGO : GameObject = Instantiate (joystickPrefab) as GameObject;
             joystickLeftGO.name = "Joystick Left";
             joystickLeft = joystickLeftGO.GetComponent.<Joystick> ();
             
             // Create right joystick
             joystickRightGO = Instantiate (joystickPrefab) as GameObject;
             joystickRightGO.name = "Joystick Right";
             joystickRight = joystickRightGO.GetComponent.<Joystick> ();            
         }

Which helps you put many control methods in, platform dependant.

And look at this!

 function Update () {
     // HANDLE CHARACTER MOVEMENT DIRECTION
     #if UNITY_IPHONE || UNITY_ANDROID
         motor.movementDirection = joystickLeft.position.x * screenMovementRight + joystickLeft.position.y * screenMovementForward;
     #else
         motor.movementDirection = Input.GetAxis ("Horizontal") * screenMovementRight + Input.GetAxis ("Vertical") * screenMovementForward;
     #endif


Input.GetAxis ("Horizontal") and Input.GetAxis ("Vertical")

Brilliant eh?

It does pay to check out the Input manager, but to be honest I don't use it.

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
avatar image
0

Answer by Hyperion · Aug 30, 2013 at 12:47 AM

I won't be specific, but the way you do it without using the code in that tutorial is to set buttons as the Player Joystick buttons so that later you can say in your script:

if (Input.GetButtonDown("yourJoystick")){

//connect to the state machine and do desired action

}

Comment
Add comment · Show 10 · 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 Triqy · Aug 30, 2013 at 10:50 PM 0
Share

would i need to change the input settings in the player prefrences to do this?

the joysticks are GUIs on mobile devices that you can move around on the screen by touching them

avatar image Hyperion · Aug 30, 2013 at 11:58 PM 0
Share

Yes. Unfortunately I am not so experienced with touch screen controls, but knowing $$anonymous$$ecanim, all you need to do to make it work is SO$$anonymous$$EHOW manipulate its parameters in the state machine. ($$anonymous$$g. you want to get to this: yourAnimator.SetBool("ExampleVariable",true) inside the code, and it'll work.) If you need any help with the $$anonymous$$ecanim side of coding, feel free to ask!

avatar image meat5000 ♦ · Aug 31, 2013 at 12:36 AM 0
Share

$$anonymous$$ecanim has no real bearing on the control method. Just GetAxis and AddForce in the direction you need. Statemachine should be set to handle the rest.

avatar image Hyperion · Aug 31, 2013 at 12:52 AM 0
Share

Yup, I agree with meat5000. As long as your GUI manipulates the state machine, $$anonymous$$ecanim will work. It's exactly like normal $$anonymous$$ecanim, except the interaction buttons are different.

avatar image meat5000 ♦ · Aug 31, 2013 at 01:04 AM 0
Share

Check how awesome I am at ripping code, below :P

That AngryBots tutorial has some awesome stuff worth learning in it!

Show more comments

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

17 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

Related Questions

How to convert script so that it uses Mobile inputs 1 Answer

How to not always show first frame of animation 1 Answer

Making 3D character run left and right in a 2D environment. 1 Answer

AddMixingTransform with Mecanim 1 Answer

Add more bones to skeleton - vertebraes definition...? 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