Answer the question
In order to leave comments, you need to log in
Object not moving in unity?
Hello, I copied a script from one Internet resource for managing a sphere in unity. Here is the code:
void FixedUpdate() {
if ( netView.isMine ) { // если обькт принадлежит нам то мы им управляем иначе делаем интерполяцию движения
float inputX = Input.GetAxis( "Horizontal" );
float inputY = Input.GetAxis( "Vertical" );
if ( inputX != 0.0f ) {
rigidbody.AddTorque( Vector3.forward * -inputX * power, ForceMode.Impulse );
}
if ( inputY != 0.0f ) {
rigidbody.AddTorque( Vector3.right * inputY * power, ForceMode.Impulse );
}
} else {
syncTime += Time.fixedDeltaTime;
rigidbody.position = Vector3.Lerp( syncStartPosition, syncEndPosition, syncTime / syncDelay ); // интерполяция перемещения
rigidbody.rotation = Quaternion.Lerp( syncStartRotation, syncEndRotation, syncTime / syncDelay ); // интерполяция поворота
}
}
Answer the question
In order to leave comments, you need to log in
You also need to get the rigidbody via GetComponent
public float torque;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float turn = Input.GetAxis("Horizontal");
rb.AddTorque(transform.up * torque * turn);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question