Hello!
I am wanting to make a cube move 1 in the x position.
I’ve tried a couple of things but none have worked.
If you know how to do this, please tell me below, Thanks.
Thanks, just what I needed.
I am wanting it to be less jumpy so it doesn’t just go right to the new position, but instead slide to it.
I am thinking of adding an animation that goes with it, but please tell me if there is a better way.
Thanks!
rb.addForce(transform.forward * speed);
where speed is a public variable. You can also write - rb.addForce(1,0,0,speed); - in place of transform.forward if the body moves on z-axis in place of x-axis.
If you want it to stop just do this
private Rigidbody rb;
public float speed = 5;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown(KeyCode.W))
rb.AddForce(transform.forward * speed);
if (Input.GetKeyDown(KeyCode.S))
rb.AddForce(transform.forward * -speed);
}