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 /
avatar image
0
Question by ro88y88 · Jul 04, 2019 at 01:50 AM · accelerometertiltbalance

I need to add resistance to my balance app.

Have a balance game and i need help with the code. right now the way the code is the objects can be held in one spot with no resistance. i would like for the objects to tilt on there own to make it harder.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class acclEM : MonoBehaviour {

 //public float speed = Random.Range (7,30);
 public float speed = 5f;

 void OnEnable()
 {

     transform.rotation = Quaternion.Euler(0, 0, 0);
 
 }





 void LateUpdate (){

     float temp = Input.acceleration.x;


     transform.Rotate (0, 0, -temp * speed);

 }

}

Comment
Add comment · Show 6
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 DCordoba · Jul 04, 2019 at 02:31 AM 0
Share

some simple random titl? like?

 float unstable = 5f;
 //public float speed = Random.Range (7,30);
 public float speed = 5f;
 void OnEnable()
 {
     transform.rotation = Quaternion.Euler(0, 0, 0);
  }
  void LateUpdate (){
      float temp = Input.acceleration.x;
      transform.Rotate (0, 0, -temp * speed);
      if(temp<.01f){//if there is manual rotation disable random
            float rand = Random.Range(-unstable, unstable);
            transform.Rotate (0, 0, rand);
      }
 }
avatar image ro88y88 DCordoba · Jul 04, 2019 at 03:10 AM 0
Share

its what im looking for but its really twitchy is there a way to make it smoother?

avatar image ro88y88 DCordoba · Jul 04, 2019 at 03:32 AM 0
Share

Or maybe have it start going the the opposite direction after a couple seconds. I'm looking for the kinda balance like in a skateboard manual if you know what I'm saying.

avatar image DCordoba ro88y88 · Jul 04, 2019 at 02:40 PM 0
Share

hummm, probably you will need a more complex function, capable to iterate between a sequence of frames, some like?

 public float SequenceDuration;//the duration between one change and another
 float counter = 0f;

 float unstable = 5f;
 //public float speed = Random.Range (7,30);
 public float speed = 5f;
 void OnEnable()
 {
     transform.rotation = Quaternion.Euler(0, 0, 0);
     RestartSequence();
 }
 void LateUpdate (){
     float temp = Input.acceleration.x;
     transform.Rotate (0, 0, -temp * speed);
     //if there is manual rotation disable random
     if(temp<.01f){
         UpdateRandomSequence();
     }
 }

 void UpdateRandomSequence(){

     if (SequenceDuration < counter) {
         RestartSequence();
     }

     //simple, clumsy lerping...
     transform.Rotate (0, 0, rand*(Time.deltaTime/SequenceDuration));

     counter += Time.deltaTime;

 }

 /// <summary>
 /// Store the random value, exculsive initialized of this function 
 /// </summary>
 float rand;
 void RestartSequence(){
     rand = Random.Range(-unstable, unstable);
     counter = 0f;
 }
Show more comments

0 Replies

· Add your reply
  • Sort: 

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

109 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

Related Questions

How to create tilt control similar to temple run? 0 Answers

Move if mobile tilts in positive Y direction 0 Answers

iPad: accelerator tilt breaks collider 3 Answers

Rigidbody2D with Accelerometer 0 Answers

input.acceleration - change the zero position of the phone? 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