Im trying to create a 2D scrolling shootemup. What i am trying to do is have the camera auto scroll in a
chosen direction which is determined by trigger points on the scene.
I have created the following items:
- a 2dtilemap level
- a gameobject which i have attached the camera called Camera_Pilot. I have added borders around this gameobject too keep the player inside this area.
- a Player character
- a trigger point called Camera_Director
The problem I am having is that the player seems to travel quicker if moving in the same direction as the Camera compared to moving in the opposite direction as the camera.
Camera scrolling to the right, the player travels faster to the right, and slower to the left. Same for diagonals.
I did try having the Player as a child of the Camera_Pilot but got the same result.
Camera_Pilot code:
public class CameraPilot : MonoBehaviour
{
public float moveSpeed;
public float travelDirectionX = 1;
public float travelDirectionY = 0;
//private Vector2 moveInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position += new Vector3(travelDirectionX * Time.deltaTime * moveSpeed, travelDirectionY * Time.deltaTime * moveSpeed, 0f);
}
}
Player movement code:
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public GameObject cameraPilot;
private Vector2 moveInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
moveInput.x = Input.GetAxisRaw("Horizontal");
moveInput.y = Input.GetAxisRaw("Vertical");
moveInput.Normalize();
transform.localPosition += new Vector3(moveInput.x * Time.deltaTime * moveSpeed, moveInput.y * Time.deltaTime * moveSpeed, 0f);
}
}
TIA