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
0
Question by anggarp · Dec 05, 2015 at 04:22 AM · movingaccelerometerlimit

Accelerometer moving limit. Help me please!

Please help me! I had a problem with my final project game 2D, i tried to use accelerometer control for my project, but i had a problem, my character game (motor) still can move out of the track if i tilt my android device. if i tilt to the left, character wil get stuck on the left of track, if i tilt to the right, character will be out of the track. i want make a limit position for the character but i dont know the code to make limit access for my character, i tried many different way on youtube to make that happen, but still didnt work. if somebody can help me, im very thankful for that :) please...

this is my script character controller:

 using UnityEngine;
 using System.Collections;
 
 public class motorController : MonoBehaviour {
 
    
     public float motorSpeed;
     public float maxPos = 2.5f;
     
 
     Vector3 position;
     public uiManager ui;
     public audioManager am;
     public audioManager ad;
     
 
     private scoreManager theScoreManager;
 
     void Awake() {
         am.motorSound.Play();
     }
 
 
     // Use this for initialization
     void Start () {
 
         position = transform.position;
 
         theScoreManager = FindObjectOfType<scoreManager>();
 
     }
     
     // Update is called once per frame
     void Update () {
 
         theScoreManager.scoreIncreasing = true;
 
         // Coding accerleration move character
         float temp = Input.acceleration.x ;
 
         if ((transform.position.x < 2.5 && Input.acceleration.y > 0) || (transform.position.x > -2.5 && Input.acceleration.y < 0))
 
             transform.Translate(temp, 0, 0 * motorSpeed);
 
     }
 
     void OnCollisionEnter2D(Collision2D col){
         if(col.gameObject.tag == "mobil musuh")  {
             Destroy (gameObject);
             ui.gameOverActivated();
             am.motorSound.Stop();
             ad.crashSound.Play();
 
 
             theScoreManager.scoreCount = 0;
             theScoreManager.scoreIncreasing = false;
 
         }
     }
 
 
 }
 


THIS THE PICT MY GAME 2D: alt text

1.jpg (293.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JedBeryll · Dec 05, 2015 at 11:28 AM

Before moving your object you should check where it is going to move when applying force. so the right way of doing this is:

  • get motor position

  • get input.acceleration

  • add those together and check if the bike is going to be in the track

  • if it is, move the bike to the position

Comment
Add comment · Show 2 · 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 anggarp · Dec 05, 2015 at 11:37 AM 0
Share

can u made the correct script accelerometer control for my project? because i still dont understand, i just wanna move the bike left and right, but i want the bike do not cross the track so i made max position left and right is -2.25, 2.5. thx u so much! sorry if my english so unwell :)

avatar image JedBeryll · Dec 05, 2015 at 11:51 AM 0
Share

i never used input.acceleration so i would just be guessing

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

34 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

Related Questions

Moving to certain direction 1 Answer

WWW WP8 Cache? Maybe requests limit? 0 Answers

How to clamp transform.Rotate values? 0 Answers

Detect when near edge of an object (3D) 0 Answers

Como posso mover GameObjects de mesmo script de forma independente? 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