So I’m trying to make a Gyruss remake here and I’m working on the movement to get the ship to move in a circular pattern. I’ve run into a problem, here is an early version of my code.
using UnityEngine;
using System.Collections;
public class PlayerControl : ShipClass
{
public Transform shotStart;
public PlayerShot shot;
void FixedUpdate ()
{
int xAxisValue = (int) Input.GetAxis ("Horizontal");
int yAxisValue = (int) Input.GetAxis ("Vertical");
switch(xAxisValue)
{
case 1:
transform.Rotate (0, 0, p_rotateSpeed);
transform.Translate (1 * p_Speed * Time.deltaTime, 0, 0);
break;
case -1:
transform.Rotate (0, 0, -p_rotateSpeed);
transform.Translate (-1 * p_Speed * Time.deltaTime, 0, 0);
break;
default:
break;
}
switch(yAxisValue)
{
case 1:
transform.Translate (0, -1 * p_Speed * Time.deltaTime, 0);
break;
case -1:
transform.Translate (0, 1 * p_Speed * Time.deltaTime, 0);
break;
default:
break;
}
if (Input.GetButtonDown ("Fire2"))
{
Debug.Log ("Fire2 pressed!");
Instantiate(shot, shotStart.position, shotStart.rotation);
}
/*
*
* Debug Purposes
*
*
if(Input.GetKey("a"))
transform.Translate (-1 * player.p_Speed * Time.deltaTime, 0, 0);
if (Input.GetKey ("d"))
transform.Translate (1 * player.p_Speed * Time.deltaTime, 0, 0);
if (Input.GetKey ("s"))
transform.Translate (0, -1 * player.p_Speed * Time.deltaTime, 0);
if (Input.GetKey ("w"))
transform.Translate (0, 1 * player.p_Speed * Time.deltaTime, 0);
Debug.Log (Input.GetAxis ("Vertical"));
*/
}
}
Here’s my problem. I start the game. And I’ll move the ship to the left or right it doesn’t really matter and everything works fine and dandy. When I decide to go back the other direction however and stop it at its starting position I notice that the ship has moved further up on the screen. I think that it is because that the rotate and translate statements don’t happen at the same time but I have no clue of a workaround for this. Does anyone know of a way to fix this problem? Thanks in advance.