# New to Unity Trying to make my model rotate just a little but cant do it (C#)

so im trying to make a learning project in a similar vein to star fox, on rails spaceship shooter etc. ive got it so my ship flys forward but when i press left or right i want it to rotate slightly on the z-axis before moving. ive found 2 outcomes to my code so far. 1.) a single press rotates all the way to 180 degrees. or 2.) it only rotates 2 degrees the wont rotate any more.

this is the code im currently using :

``````using UnityEngine;
using System.Collections;

public class playerController : MonoBehaviour {

//initialize the members
Vector3 upVector=new Vector3(0,1,0);
Vector3 forwardVector=new Vector3(0,0,1);
public Transform player;

Quaternion rotation;
public int speed=5;
// Use this for initialization
void Start ()
{
rotation=player.rotation;
rotation.x+=89;
}

// Update is called once per frame

void Update ()
{
float angle_z=0;
float angle_x=0;
float max_z=340;
float min_z=20;
if(Input.GetAxisRaw("Horizontal")>0)
{
if(player.rotation.z<max_z || player.rotation.z==0)
{
angle_z++;
angle_z*=-(3.14f/180);
}
}
else
{
if(Input.GetAxisRaw("Horizontal")<0)
{
if(angle_z>min_z)
{
angle_z=1;
angle_z*=-1;
}
}
else
{
angle_z=0;
}
}

player.rotation=new Quaternion(player.rotation.x,player.rotation.y,player.rotation.z + angle_z , player.rotation.w);
//move forward based on the rotation axis
rotation=player.rotation;
var absoluteDirection = rotation * Vector3.forward;
transform.position += (absoluteDirection * Time.deltaTime)*speed;
}
}
``````

and the transform player is the ship itself as i was getting errors when i tried to use this.transform. please help.

well i figured out the issue, turned out something wierd was happening with mathf.convert to radians, no matter what i set the number of degrees to for max z rotation i got .017 , manually entering .348888f fixed it

I think your making this WAY too complicated. by the way, i like C++ for programming, but javascript is much easier than c# for scripting in unity, i suggest you try it out. anyway. if you want to rotate while holding down left or right button, you could do something like. btw this is in javascript, but you can translate it to c# easy enough, and also im using a and d for left and right because i dont feel like lookin up the thing for left and right arrow.

that SHOULD work, I think that specific part of the code would be EXACTLY the same in c#

hope i helped.