I am a beginner at Unity, so I am just trying to do some basic stuff. I wanted to try to
make a bar move horizontally in 2D mode, and I did it. Then I noticed it was taking time to start
moving,accelerate, and change direction because it follows force = mass x acceleration, but I don’t want that.
With the docs and scripting API, I found that I should use a 2D Impulse force to solve my problem.
I just don’t know how to fix my current code to use the impulse force instead, even though I have
tried it many times in different ways. This is the code I am using:
using UnityEngine;
using System.Collections;
public class Control : MonoBehaviour {
public float speed;
private Rigidbody2D rb;
void Start ()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector2 movement = new Vector2 (moveHorizontal, 0);
rb.AddForce (movement * speed);
}
}