How to get Y-Axis movement in 2D space shooter.
So I have a spaceship shooter game I'm working on which is basically a knock off of everyone's favorite retro spaceship shooter. You know the one. Anyway, I need some help getting movement along the Y-axis to work. I'm using this script for horizontal but I'm having trouble with vertical.
// update the position of the ship based on "horizontal" input void UpdatePosition() { //move the player laterally in the 'X' coordinate movement.x = Input.GetAxis("Horizontal") * Time.deltaTime * MoveSpeed; // apply the movement vector to the game object's position gameObject.transform.Translate(movement); // Transform the 3D world position to a screen pixel location Vector3 screenPosition = CameraObject.WorldToScreenPoint(gameObject.transform.position); // off screen to the right? if (screenPosition.x > Screen.width) { // clamp (reset) to the screen's right side screenPosition.x = Screen.width; // Transform clamped screen position to world space and // assign to player ship gameObject.transform.position = CameraObject.ScreenToWorldPoint(screenPosition); } // off Screen to the left? else if (screenPosition.x < 0) { // clamp (reset) to the screen's left side screenPosition.x = 0; // Transform clamped screen position to world space and // assign to player ship gameObject.transform.position = CameraObject.ScreenToWorldPoint(screenPosition); } }
Your answer
Follow this Question
Related Questions
Display UI Panel on 2D Box Collider Trigger 0 Answers
Main Menu Help 2 Answers
Script to animation and movement of 2d player 1 Answer
how do I make 2 player sprites not interact? 0 Answers
Cannot delay player respawn. 2 Answers