I’m having trouble to figure out why this is happening, i’ve googled it but to no avail, if anyone could help i would be thankful. This code isn’t finished yet, i’m putting together all the player control scripts i’ve written. Anyway, there goes my code:
public class Tesla : MonoBehaviour
{
[SerializeField] float turnSpeed = 100f;
[SerializeField] float pitchSpeed = 50f;
[SerializeField] float rollSpeed = 100f;
[SerializeField] float initialVelocity = 0.0f;
[SerializeField] float finalVelocit = 500.0f;
[SerializeField] float currentVelocity = 0.0f;
[SerializeField] float accelerationRate = 10.0f;
[SerializeField] float decelerationRate = 50.0f;
public float startFOV = 60f;
public float maxFOV = 90f;
public float t = 0.5f;
public float Bullet_Forward_Force;
public Camera myCamera;
public GameObject Bullet_Emitter;
public GameObject Bullet_Emitter2;
public GameObject Bullet;
public AudioClip SoundEffect;
Transform myT;
void Awake()
{
myT = transform;
}
void Update()
{
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Turn();
if (Input.GetKey("w"))
{
myCamera.fieldOfView = Mathf.Lerp(myCamera.fieldOfView, maxFOV, t);
}
else
myCamera.fieldOfView = Mathf.Lerp(myCamera.fieldOfView, startFOV, t);
if (Input.GetKey("w")) //This makes the gameObject accelerate when the "w" is being pressed
{
currentVelocity = currentVelocity + (accelerationRate * Time.deltaTime);
transform.Translate(0, 0, currentVelocity);
}
else
{
currentVelocity = currentVelocity - (decelerationRate * Time.deltaTime);
if (currentVelocity > 0) //This checks if the current velocity is 0
{
transform.Translate(0, 0, currentVelocity);
}
else
{
transform.Translate(0, 0, 0);
}
}
currentVelocity = Mathf.Clamp(currentVelocity, initialVelocity, finalVelocit);
}
void Turn() //This is where i am having trouble.
{
float yaw = turnSpeed * Time.deltaTime * Input.GetAxis("Mouse X");
float pitch = pitchSpeed * Time.deltaTime * Input.GetAxis("Mouse Y");
float roll = rollSpeed * Time.deltaTime * Input.GetAxis("Roll");
myT.Rotate(-pitch, yaw, roll);
}
}
}