Hey Guys, i just started experimenting with Unity and I began with a little space shooter project.
I want my GameObject to rotate around the z axis if I am pressing the left or right arrow key and I want to move it in the facing direction if I am pressing up or down arrow key.
This is my solution right now:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
float InputX;
float InputY;
void Start ()
{
}
void Update ()
{
InputX = Input.GetAxis("Horizontal");
InputY = Input.GetAxis("Vertical");
}
void FixedUpdate()
{
if(InputX != 0)
{
transform.Rotate(-Vector3.forward * InputX);
}
if(InputY != 0)
{
transform.Translate(transform.up * InputY);
}
}
}
With this script i can rotate and move the player but after the Player is rotated in a direction its not moving in the facing direction.