Hello. I am new to Unity.
I have a question about the movement of Rigidbody2D.
I add a sprite with Rigidbody2D to the 2d scene.
Player movement script:
private Vector2 movement;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
movement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
private void FixedUpdate()
{
rb.AddForce(movement * 4000 * Time.fixedDeltaTime);
}
Script on camera:
private GameObject player;
void Start()
{
player = GameObject.FindWithTag("Player");
}
void Update()
{
Vector3 moveTo = new Vector3(player.transform.position.x, player.transform.position.y, -10f);
transform.position = Vector3.Lerp(transform.position, moveTo, 10.0f * Time.deltaTime);
}
When I start the game, the player moves with shaking, not smoothly. How to avoid this?
Thanks.