- Home /
Space Shooter Player 2 ship is flipping when going into Play Mode
Hello everyone!
I'm modifying the Space Shooter Tutorial so that I can have 2 Players simultaneously (Offline Multiplayer).
I used part of the Couch Wars tutorial to learn how to assign different Inputs to the different players...so far, so good. I can control each Space Ship independently :)
Now, I want the Second Player (Red Ship) to look down at Player 1 (Blue Ship) when the game starts.
For this I did the following:
Duplicated the Ship Prefab in the Hierarchy
Change it's name to Player_P2
Changed the Inputs in the Inspector
Rotated manually the Red Ship 180 degrees in Y and moved it up in the Z Axis
Now i'm left with this:
The problem is that when I go into Play Mode, the Red Ship flips and looks "up".
This is how my Hierarchy looks.
This is how my Input > Axes looks.
This is how the Player2 Inspector looks.
And this is the PlayerController code:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Limite
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
public float fuerza, fuerzagiroz, fuerzagirox;
public Limite lim;
public string Disparar = "Fire_P1";
public string MovimientoHorizontal = "Horizontal_P1";
public string MovimientoVertical = "Vertical_P1";
public GameObject Disparo;
public Transform SpawnDisparo;
public float FrecuenciaDisparo;
private float siguienteDisparo;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float movimientoHorizontal = Input.GetAxis (MovimientoHorizontal);
float movimientoVertical = Input.GetAxis (MovimientoVertical);
Vector3 movimiento = new Vector3 (movimientoHorizontal, 0f, movimientoVertical);
rb.velocity = movimiento * fuerza;
rb.rotation = Quaternion.Euler (rb.velocity.z * fuerzagirox, 0f, rb.velocity.x * -fuerzagiroz);
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, lim.xMin, lim.xMax) ,
0f,
Mathf.Clamp(rb.position.z, lim.zMin, lim.zMax)
);
}
void Update()
{
if (Input.GetButton (Disparar) && Time.time > siguienteDisparo)
{
siguienteDisparo = Time.time + FrecuenciaDisparo;
Instantiate (Disparo, SpawnDisparo.position, Quaternion.identity);
}
}
}
Your answer
Follow this Question
Related Questions
Freelancer of Freespace type Enemy Ai 2 Answers
[2D] How to instantiate laser when player rotates? 1 Answer
Strategies for Physics-based Movement for 2D Space RTS Controls? 1 Answer
How can i change the player controls in Space Shooter to Touch. 1 Answer
Performance view over spawn waves method 0 Answers