I have a simple side-scroller with a capsule player and a projectile spawn on the right side of the player. The game works fine, allowing me to shoot projectiles to the right. The only problem: I can only shoot in one direction. How can I make the player face the direction it is moving, so I can fire projectiles both left and right. This is my current script so far that is attached to my player:
using UnityEngine;
public class Player : MonoBehaviour // The class was missing, I improvised (Berenger)
{
public float moveSpeed = 10f;
public float rotateSpeed = 5f;
// Update is called once per frame
void Update ()
{
float moveForward = moveSpeed * Time.smoothDeltaTime * Input.GetAxis("Vertical");
float moveleft = moveSpeed * Time.smoothDeltaTime * Input.GetAxis("Horizontal");
float rotate = rotateSpeed * Time.smoothDeltaTime * Input.GetAxis("Horizontal");
transform.Translate(Vector3.forward * moveForward);
transform.Translate(Vector3.back * moveleft);
if(Input.GetKeyDown(KeyCode.Space))
rigidbody.AddForce(Vector3.up * 500);
}
}