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 mkobaner · Mar 20, 2016 at 09:58 AM · scriptingbasics

Calibration of accelerometer with offset

Hello,

I try to get input x and y value at the beginning and create and offset value, after that in every update current x - offset x = movement vector but i get an error . New to programming and any help is appreciated.

Assets/Scripts/Movementacc.cs(40,46): error CS1525: Unexpected symbol =' Assets/Scripts/Movementacc.cs(41,46): error CS1525: Unexpected symbol ='

 using UnityEngine;
 using System.Collections;
 
 public class Movementacc : MonoBehaviour {
 
     public float speed;
     public float speed1;
     public float jumpforce;
     private Rigidbody rb;
 
     public AudioClip jumpSound;
     private AudioSource SoundSource;
 
     public GameObject ballParticle;
 
     public float offSetX;
     public float offSetY;
     public float cX;
     public float cY;
 
     public void Calibrate()
     {
         Input.acceleration.x=offSetX;
         Input.acceleration.y=offSetY;
     
     }
 
 
 
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
         SoundSource = GetComponent<AudioSource>();
         Calibrate ();
     }
     
     void FixedUpdate ()
     {
 
         Input.acceleration.x-offSetX = cX;
         Input.acceleration.y-offSetY = cY;
 
         Vector3 movement2 = new Vector3(cX, 0.0f, cY);
 
 
         rb.AddForce(movement2 * speed * Time.deltaTime);
         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
 
         rb.AddForce(movement * speed1 * Time.deltaTime);
     }
 
     void OnCollisionEnter (Collision col)
     {
         Vector3 jumpvec = new Vector3 (0.0f, 1.0f, 0.0f);
         if(col.gameObject.name == "JumpPad")
         {
             rb.AddForce(jumpvec*jumpforce);
             SoundSource.PlayOneShot(jumpSound,1.0f);
         }
     }
 
 
 
 }
 
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
Best Answer

Answer by MichalOp · Mar 20, 2016 at 10:32 AM

You used "=" symbol in a wrong way, because it assigns the right side value to the left side. If you use it to assign the left side value to the right side, it will make no sense for the compiler.

You should write: cX = Input.acceleration.x-offSetX ; cY = Input.acceleration.y-offSetY ;

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 mkobaner · Mar 20, 2016 at 10:39 AM

Thanks,

I just learned another thing and had another error there " Input.acceleration.x=offSetX; nput.acceleration.y=offSetY;" swapped values and code doesnt give anymore errors thanks :).

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 Ali-hatem · Mar 20, 2016 at 10:57 AM 0
Share

why you use Input.GetAxis("") with acceleration type of game

avatar image mkobaner Ali-hatem · Mar 20, 2016 at 10:59 AM 0
Share

I test levels on pc; there might be easier way to do it but it worked ok so far.

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

40 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

Related Questions

What is Mono? Is it a compiler? A language? Or what? 3 Answers

What is Vector3, Vector4, etc.? 2 Answers

Does Unity support multiple Inheritance? 3 Answers

Player kill enemy by stepping on it. 2 Answers

Loading texture2d by script null instance 1 Answer


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