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 frankmail007 · Dec 25, 2013 at 06:48 AM · mobilecharactercontroller

Is there a character controller for mobile?

There is a built-in Character controller in Unity 3d 4.3. I'm wondering if there is a character controller for mobile platform that I can use touch or accelerometer to controller the movement of the character?

Or if there is a tutorial about how to modify the built-in character controller to support mobile platform?

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Morden · Sep 08, 2014 at 04:13 AM

The Why What Benproductions is trying to point out is that the CharacterController is one component that can be added to an object, and only handles the physics, not the movement. When you add one of the prefab character controllers (First Person Controller or Third Person Controller) to your game, you get an object with CharacterController attached, plus a CharacterMotor script and either the FPSInputController or ThirdPersonInputController (along with ThirdPersonCamera for the Third Person controller). These input controllers are what determine how the character actually moves. They direct the CharacterController to move, it merely handles collisions and such. So to move to a platform type game, you remove the current input controller script and add the PlatformInputController script. So if you wanted to handle different controls for android, you would either modify one of these input controller scripts, or roll your own with whatever controls you want for the mobile.

The How For the FPSInputController script and the PlatformInputController, one of the first lines in Update is something like:

var directionVector = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

Just change that line to use whichever parts of Input.accelerometer you want to use. A simple version that I did is just changing it to

var v = new Vector2(Input.acceleration.x, Input.acceleration.y).normalized;

var directionVector = new Vector3(v.x, v.y, 0);

That requires you to play with your tablet flat on a table, and doesn't allow any real zero point, so you always move. You would probably want to implement something in your interface to offset the acceleration vector to allow your player to hold the tablet however they wanted. You would probably also want to change the next lines, that check to see if the directionVector magnitude is > 0, to be something other than 0 to allow a "dead zone".

To do touch will be slightly more complicated, and will depend on how you want to do it. The simplest way I can think of is to set a static Vector2 called AimPoint in your InputController class that is accessible from other scripts. Then whenever you detect a touch on your game field, set AimPoint to the world coordinate. Then the inputController would calculate directionVector as an offset from the current position to the AimPoint. This should have your character moving toward wherever you touch.

For the third person controller, it's more complicated. I haven't dug into the code completely, but it looks like it is slowly applying your direction changes and such to get smooth cornering. But it still boils down to changing the input axes (plus however you want to handle jumping). Update calls UpdateSmoothedMovementDirection, which then sets v to Input.GetAxisRaw("Vertical") and h to Input.GetAxisRaw("Horizontal"). Just change those to set to either an offset/normalized vector to your touch location, or to the appropriate components of the acceleration vector.

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 Benproductions1 · Dec 25, 2013 at 07:40 AM

Hello,

The "Built-in" Character Controller does not come with any standard controls. It is merely a platform for character like movement which you have full implementation control over. It's a component comparable to the Rigidbody in many ways and just like it, has no mobile/desktop version. You also cannot modify the "built-in" Character Controller unless you decompile the Unity Editor and/or Physx which I think is against the terms and conditions.

Hope this helps,
Benproductions1

Comment
Add comment · Show 5 · 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 frankmail007 · Dec 25, 2013 at 12:42 PM 0
Share

Then if it's possible to write an "adapter" to convert mobile touch input to keyboard (axis) movement? I think this should be very common usage. There must be somebody did this already. Anybody want to share ?

avatar image Benproductions1 · Dec 26, 2013 at 02:01 AM 0
Share

AS I said The character controller doesn't take any input. What So Ever. Not from the keyboard, not from anything! The CharacterController component is merely another interface to the physics engine allowing for character like movement. How you perform this movement is up to you.

avatar image frankmail007 · Dec 27, 2013 at 01:42 AM 0
Share

If I'm not wrong, I saw a tutorial about changing the Character Controller to support 2d only. That means it's possible to change the character controller script. Am I right?

avatar image william9518 · Dec 27, 2013 at 01:46 AM 0
Share

You don't change the CharacterController in order to make it move, you use it in order to make its functions to make it move.

avatar image Benproductions1 · Dec 27, 2013 at 01:52 AM 0
Share

It's not a tutorial on changing the CharacterController for 2D. It's a tutorial on how to use the functions of the CharacterController component to act as a 2D object. Stop trying to argue, it's a matter of fact! Without decompiling the game engine, You cannot change or edit the CharacterController.

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

21 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

Related Questions

Mobile - Jumping while moving - Standard Assets 0 Answers

Simple Unity3d Facebook Integration? 1 Answer

Cloud recognition in Vuforia 0 Answers

General Unity 2D Character/Environment Control Questions 2 Answers

Character Controller Initial Problem With Mobile 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