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 sodapoptart88 · Oct 29, 2020 at 03:21 PM · inputtouch controls

How to implement android touch input joysticks for the lego microgame

So I have been messing around with customizing the Lego microgame. I am a fairly new user, and I think it is a fun way to learn the ins and outs (Plus my son is learning along with me and it keeps him interested).
In some previous projects I used android touch input by using this method: https://www.youtube.com/watch?v=EjFdZ9NjB3A
Where you add the joysticks and then code them as input to replace the input (with simpleinput from the asset store) on the player controller. So I have added the joysticks and I am looking around and the player movement seems to be a bit more complicated than what I have worked with before. Can someone please help me out with what code I would need to change in order to change the movement and look to left and right joysticks and the jump to a button on my canvas? I would really appreciate that and would be a major bonus if someone helps me understand the special movements that I can see in the controller script but am not sure how to enable or use. If it matters, I am using unity 2019.4.11f1 personal.
NOTE: In the following code from minifigcontroller.cs I tried changing Input.GetAxisRaw() to SImpleInput.GetAxisRaw() and then I get an error saying The name 'SimpleInput' does not exist in the current context. Thanks for any help.

 // Handle input.
             if (inputEnabled)
             {
                 switch (inputType)
                 {
                     case InputType.Tank:
                         {
                             // Calculate speed.
                             var targetSpeed = SimpleInput.GetAxisRaw("Vertical");
                             targetSpeed *= targetSpeed > 0 ? maxForwardSpeed : maxBackwardSpeed;
                             if (targetSpeed > speed)
                             {
                                 speed = Mathf.Min(targetSpeed, speed + acceleration * Time.deltaTime);
                             }
                             else if (targetSpeed < speed)
                             {
                                 speed = Mathf.Max(targetSpeed, speed - acceleration * Time.deltaTime);
                             }
 
                             // Calculate rotation speed.
                             var targetRotateSpeed = SimpleInput.GetAxisRaw("Horizontal");
                             targetRotateSpeed *= maxRotateSpeed;
                             if (targetRotateSpeed > rotateSpeed)
                             {
                                 rotateSpeed = Mathf.Min(targetRotateSpeed, rotateSpeed + rotateAcceleration * Time.deltaTime);
                             }
                             else if (targetRotateSpeed < rotateSpeed)
                             {
                                 rotateSpeed = Mathf.Max(targetRotateSpeed, rotateSpeed - rotateAcceleration * Time.deltaTime);
                             }
 
                             // Calculate move delta.
                             moveDelta = new Vector3(0, moveDelta.y, speed);
                             moveDelta = transform.TransformDirection(moveDelta);
                             break;
                         }
                     case InputType.Direct:
                         {
                             // Calculate direct speed and speed.
                             var right = Vector3.right;
                             var forward = Vector3.forward;
                             if (Camera.main)
                             {
                                 right = Camera.main.transform.right;
                                 right.y = 0.0f;
                                 right.Normalize();
                                 forward = Camera.main.transform.forward;
                                 forward.y = 0.0f;
                                 forward.Normalize();
                             }
 
                             var targetSpeed = right * SimpleInput.GetAxisRaw("Horizontal");
                             targetSpeed += forward * SimpleInput.GetAxisRaw("Vertical");
                             if (targetSpeed.sqrMagnitude > 0.0f)
                             {
                                 targetSpeed.Normalize();
                             }
                             targetSpeed *= maxForwardSpeed;
 
                             var speedDiff = targetSpeed - directSpeed;
                             if (speedDiff.sqrMagnitude < acceleration * acceleration * Time.deltaTime * Time.deltaTime)
                             {
                                 directSpeed = targetSpeed;
                             }
                             else if (speedDiff.sqrMagnitude > 0.0f)
                             {
                                 speedDiff.Normalize();
 
                                 directSpeed += speedDiff * acceleration * Time.deltaTime;
                             }
                             speed = directSpeed.magnitude;
 
                             // Calculate rotation speed - ignore rotate acceleration.
                             rotateSpeed = 0.0f;
                             if (targetSpeed.sqrMagnitude > 0.0f)
                             {
                                 var localTargetSpeed = transform.InverseTransformDirection(targetSpeed);
                                 var angleDiff = Vector3.SignedAngle(Vector3.forward, localTargetSpeed.normalized, Vector3.up);
 
                                 if (angleDiff > 0.0f)
                                 {
                                     rotateSpeed = maxRotateSpeed;
                                 }
                                 else if (angleDiff < 0.0f)
                                 {
                                     rotateSpeed = -maxRotateSpeed;
                                 }
 
                                 // Assumes that x > NaN is false - otherwise we need to guard against Time.deltaTime being zero.
                                 if (Mathf.Abs(rotateSpeed) > Mathf.Abs(angleDiff) / Time.deltaTime)
                                 {
                                     rotateSpeed = angleDiff / Time.deltaTime;
                                 }
                             }
 
                             // Calculate move delta.
                             moveDelta = new Vector3(directSpeed.x, moveDelta.y, directSpeed.z);
                             break;
                         }
                 }






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
0

Answer by netanelu · Nov 17, 2020 at 03:07 PM

I have just make it work:

Add from the assets store the joystick pack.

  1. on the project view, move the joystick pack folder from assets to asster/LEGO/scripts/LEGO Minifig

  2. the joystick pack folder is with the same folder as the MinifigController c# file.

  3. open minifigController code file, and add public var:

    public FixedJoystick joystick;

    now edit the lines

    var targetSpeed = right joystick.Horizontal; targetSpeed += forward joystick.Vertical; within case InputType.Direct:

  4. add a new canvas and add into this canvas an Fixed Joystcik.

  5. select the Pizza Boy and in the inspector select the Minifig Controller and select the joystick to be the joystick you made in section 4.

works for me :)

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 $$anonymous$$ · Nov 16, 2020 at 10:00 AM

Use the Standards Assets pack from unity

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

171 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

Related Questions

How to distinguish between two touch screens for input in android 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

How do you get position from fingerId 1 Answer

When pressing a button, it counts as pressing the screen and the button [New Input System] 0 Answers

How can we make touch controls like Hole.io/ Bumper.io? 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