I’m making a 2D Multiplayer space shooter and I the controls are used by the mouse. Right clicking will turn the ship to the point clicked and move the character. Left clicking will shoot. The problem occurs is when the player clicks in a direction the ship immediately turns. I want it to take its time and turn rather than instantly changing direction how can I do this complimenting the code I have already.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour{
Rigidbody2D rb;
private Vector2 Direction;
private Vector2 Mouse;
public float Speed = 5;
public GameObject Laser;
void Start(){
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (Input.GetButton("Fire2"))
{
rb.AddForce(transform.up * Speed);
faceMouse();
}
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void faceMouse()
{
Mouse = (Input.mousePosition);
Mouse = Camera.main.ScreenToWorldPoint(Mouse);
Direction = new Vector2(Mouse.x - transform.position.x, Mouse.y - transform.position.y);
transform.up = Direction;
}
void Shoot()
{
Instantiate(Laser, transform.position, transform.rotation);
}
}