- Home /
Why my 3dobject not moving correctly in the right direction
I have this script but my 3dobject (skier) not moving correctly in the right direction when i tilt my android, and i cannot find where the problem is!!
if(cacheMagnitude240)
{
if(fixedAcceleration.y<0)
{
ok=false;
}
}
if(transform.eulerAngles.y<140)
{
if(fixedAcceleration.y>0)
{
ok=false;
}
}
grounded=wheel.GetGroundHit(outHit);
if(grounded==false)
{
ok=false;
timeCache=Time.time;
cScript.setX();
if(processedX2==false)
{
trailParticle.emit=false;
audio.Pause();
ok2=false;
processedX2=true;
processed=false;
}
}
else
{
if(processed==false)
{
if(secObj.transform.localRotation.eulerAngles.y<300&&secObj.transform.localRotation.eulerAngles.y>60||playing==false)
{
secObj.transform.localRotation.eulerAngles.y=0;
doRagdoll();
}
trailParticle.emit=true;
audio.Play();
cScript.resetX();
processedX2=false;
processed=true;
trickType=-1;
ok2=true;
}
}
if(cacheMagnitude>3)
{
audio.volume=cacheMagnitude/40;
trailParticle.minEmission=cacheMagnitude*3;
trailParticle.maxEmission=cacheMagnitude*5.5;
if(ok==true)
{
if(Mathf.Abs(fixedAcceleration.y)>0.11)
{
wheel.steerAngle =1/(cacheMagnitude/4)*fixedAcceleration.y*turnProgression*Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.up * fixedAcceleration.y*turnProgression*2*Time.deltaTime);
}
if(ok2==true)
{
if(fixedAcceleration.y<-0.11)
{
animationComp.CrossFade("CarveRight",0.35);
}
else if (fixedAcceleration.y>0.11)
{
animationComp.CrossFade("CarveLeft",0.35);
}
else if(cacheMagnitude>(maxSpeed/2))
{
animationComp.CrossFade("Fast",0.8);
}
else
{
animationComp.CrossFade("Ski",0.8);
}
}
}
}
else
{
if(Mathf.Abs(fixedAcceleration.y)>0.11)
{
rigidbody.AddRelativeTorque (Vector3.up * fixedAcceleration.y*turnProgression*4*Time.deltaTime);
}
animationComp.CrossFade("idle",0.2);
}
}
function getWeight(acceleration:float):float
{
acceleration=Mathf.Abs(acceleration);
if(acceleration<2.1)
{
return (2.1-acceleration)*100;
}
return 100;
}
function CalibrateAccelerometer () {
var accelerationSnapshot : Vector3 = Input.acceleration;
var rotateQuaternion : Quaternion = Quaternion.FromToRotation (new Vector3 (0.0, 0.0, -1.0), accelerationSnapshot);
calibrationQuaternion = Quaternion.Inverse (rotateQuaternion);
}
No one is going to read this...
Please format your code correctly and reduce the code to relevant parts only.
Oh GOD that unreadable indentation. Code like this makes me cry :(
@rowanabejjani, you mentioned "...i cannot find where the problem is!!" Your code was hard to follow. It is a good practice before doing a any coding to get a clear picture of what you are doing. $$anonymous$$ake a plan. For example, do A, then B, if fails, do C. Then translate these steps in a readable code. If necessary use comments. I doubt you were able to follow your own code. Writing code is an art, just like cooking, gardening or brick-laying.
Don't be discouraged, I am learning too. Often, like a soccer ball, we need to be kicked around (too often) to achieve our goal.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110830im_/https://answers.unity.com/themes/thub/images/avi.jpg)