- Home /
Why this error ? - The type `UnityEngine.Vector3' does not contain a constructor that takes `1' arguments
I'm trying to recalibrate the accelerometer using a code I found on the Unity Forum HERE - When I'm trying to call the 'getAccelerometer' method inside the Update, I'm getting that error in Unity and it is not making much sense to me as to why it should. Here is the code that I'm using
Matrix4x4 calibrationMatrix;
void calibrateAccelerometer(){
Vector3 wantedDeadZone = Input.acceleration;;
Quaternion rotateQuaternion = Quaternion.FromToRotation(new Vector3(0f, 0f, -1f), wantedDeadZone);
//create identity matrix ... rotate our matrix to match up with down vec
Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, rotateQuaternion, new Vector3(1f, 1f, 1f));
//get the inverse of the matrix
this.calibrationMatrix = matrix.inverse;
}
Vector3 getAccelerometer(Vector3 accelerator){
Vector3 accel = this.calibrationMatrix.MultiplyVector(accelerator);
return accel;
}
void Start(){
calibrateAccelerometer();
}
void Update(){
Vector3 dir = new Vector3 (getAccelerometer(Input.acceleration));
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
Just a typo?
Vector3 wantedDeadZone = Input.acceleration;;
@meat5000 That was a typo indeed. Fixed. @OrbitGames The error is in the below line under Update.
Vector3 dir = new Vector3 (getAccelerometer(Input.acceleration));
Declare your Vector3 dir outside your functions then update the variable ins$$anonymous$$d of trying to direcly use a function to set its value.
Answer by tanoshimi · May 11, 2014 at 01:44 PM
Vector3 dir = new Vector3 (getAccelerometer(Input.acceleration));
should be:
Vector3 dir = getAccelerometer(Input.acceleration);
How 'bout that ! That worked alright. Thanks for chi$$anonymous$$g @tanoshimi ! $$anonymous$$uch appreciated.
Basically what tanoshimi said but declaring first then updating later :)
Vector3 dir = new Vector3.zero;
void Update(){
dir = getAccelerometer(Input.acceleration);
But he knows better than me; he actually does C# :P
Ah. So that's my bad. What I did was
Vector3 dir;
and that is why it errored out for me. Anyway, though I don't have errors in the code, the recalibration itself isn't working for me so that is another issue for me now o_O
EDIT: Well no idea what happened there, it is suddenly working alright now. Wow !
Your answer
![](https://koobas.hobune.stream/wayback/20220613144754im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I calibrate phone accelerometer? 0 Answers
how to move an object in 4 directions by tilting device when not parallel to the ground 0 Answers
Incremental acceleration with Imput 1 Answer
Map sensor(accelro+gyro) axis to unity character in realtime 1 Answer
calibrate the accelerometer for different holding positions 0 Answers