- Home /
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);
}
}
}
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 ;
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 :).
why you use Input.GetAxis("") with acceleration type of game
I test levels on pc; there might be easier way to do it but it worked ok so far.
Your answer
Follow this Question
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