- Home /
rotation speed cap in 2D
as you can see in this video: https://youtu.be/dPKu-5EtY00 the upper wheels of the box move much faster than the lower ones. another problem is the insane speed this box gains after some time. both problems can surely be fixed by simply capping out the speed at some point, but i'm not really sure how i could do such thing. to rotate the wheels, i used this script:`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class rotaet : MonoBehaviour { public float stuff = 1111f;
private float movement;
public Rigidbody2D FrontTire;
public Rigidbody2D BackTire;
public Rigidbody2D FrontTire2;
public Rigidbody2D BackTire2;
public float speed = 100;
void Update()
{
movement = Input.GetAxis("Horizontal");
}
private void FixedUpdate ()
{
BackTire.AddTorque(-movement * Time.fixedDeltaTime * speed);
FrontTire.AddTorque(-movement * Time.fixedDeltaTime * speed);
BackTire2.AddTorque(-movement * Time.fixedDeltaTime * speed);
FrontTire2.AddTorque(-movement * Time.fixedDeltaTime * speed);
}
}` any ideas?
Comment