Hi, I keep having a problem and after a lot of looking and checking my code I cannot solve it, so I am looking for some help! My game is a 2d game using 3d models with a top down view. I am trying to move a 3d model spaceship back and forth and let it rotate to the left when i move left, and to the right when I move right. That part seems to be working, but I feel that my problem lies in there somewhere. If I move too much, my spaceship starts to fall down (this is imperceptible in game view, except that the bullets that it fires go below my enemies and do not hit them).
here is my code
public class ShipMove : MonoBehaviour {
public float speed = 3.0f;
public GameObject bullets;
public float spacing;
float shipdir;
float timer = 0.2f;
Quaternion shiprot;
void Update () {
float translation = Input.GetAxis("Horizontal") * speed;
transform.Translate(translation,0,0);
if((translation - shipdir) > 0){
shiprot = Quaternion.Euler(0,0,-25);
// transform.rotate (0,0,25);
}
if((translation - shipdir) < 0){
shiprot = Quaternion.Euler(0,0,25);
// transform.Rotate(0,0,-25);
}
if((translation - shipdir) == 0){
shiprot = Quaternion.Euler(0,0,0);
// transform.Rotate(0,0,0);
}
transform.rotation = shiprot;
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
timer -= Time.deltaTime;
if(Input.GetButton("Fire2") timer <= 0.0f){
Instantiate(bullets, pos, rot);
timer = spacing;
}
shipdir = translation;
}
}
I’m not sure if I’m being clear or specific enough with my description of the problem.