- Home /
This post has been wikified, any user with enough reputation can edit it.
rigidbody player jump automatically.
I code one cube in rigidbody to move with rotate but when the "x face" of cube contact with ground the cube is jump automatically.
my code is :
void FixedUpdate() {
float mv = rotationSpeed * Time.fixedDeltaTime * Input.GetAxis("Horizontal");
//Debug.Log(mv);
rigidbody.AddRelativeTorque( new Vector3(forceAmount * Input.GetAxis("Vertical"), 0.0f, 0.0f));
//rigidbody.AddRelativeTorque( new Vector3(forceAmount * Input.GetAxis("Horizontal"), 0.0f, 0.0f));
float rottatedGer = transform.eulerAngles.z ;
// go to front or back
// if greater than 270 go back else go front
if ((rottatedGer < 269) && (rottatedGer > 91) ){
Debug.Log(rottatedGer);
if (rottatedGer < 271){
transform.Rotate(0.0f,0.0f, rottatedGer -90);
}else if(rottatedGer >89){
transform.Rotate(0.0f,0.0f,rottatedGer +90);
}
}else{
transform.Rotate(0.0f,0.0f,mv*-1);
}
transform.Translate(new Vector3( mv * 3 * Time.deltaTime,0.0f, 0.0f));
}
Now how I can fix it that don't jump when I try to go to right.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613115819im_/https://answers.unity.com/themes/thub/images/avi.jpg)