Help with Movement Script

With the help of some friends I made a movement script for a 3d game I’m making. The script is supposed to allow the player to move a vehicle forward & backwards and then turn the vehicle. The script itself doesn’t return any errors, but in game the vehicle immediately starts rotating to the right, speeding up if it’s left alone and if it makes a full 180 degree turn, then the controls invert. So I was wondering if anyone could help figure out what is wrong with the script. It’s coded in CSharp.

using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;

public class MoveScript : MonoBehaviour {

    public float mySpeed;
    public float speed = 5.0f;

    private Boolean canMove;
    private Boolean turnLeft = false;
    private Boolean turnRight = false;
    private float rotationVal;
    private float temp = 0f;
    private Transform myTransform;

    Rigidbody obj;
    float camRayLength = 100f;
    int wallMask;


    void Awake()
    {
        wallMask = LayerMask.GetMask("Walls");
        obj = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (canMove)
        {
            if (Input.GetKeyDown("left"))
            {
                turnLeft = true;
                //TurnLeft();
            }
            if (Input.GetKeyDown("right"))
            {
                turnRight = true;
                //TurnRight();
            }
        }

        Vector3 moveDir = Vector3.zero;
        //moveDir.y = Input.GetAxis("Horizontal");

        //transform.Rotate(moveDir);

        transform.position += mySpeed * Time.deltaTime * (moveDir * 2f);

        Vector3 speedUp = Vector3.zero;
        moveDir.x = Input.GetAxis("Vertical");

        transform.position += mySpeed * Time.deltaTime * -moveDir;

        //Turning();
       
    }

    void LateUpdate()
    {
        if (turnLeft)
        {
            if (temp > 90)
            {
                turnLeft = false;
                temp = 0f;
            }
            else
            {
                rotationVal = Mathf.Lerp(0f, 90f, Time.deltaTime);
                myTransform.Rotate(0, rotationVal, 0);
                temp += rotationVal;
            }

        }
        else if (turnRight)
        {
            if (temp < -90)
            {
                turnRight = false;
                temp = 0f;
            }
            else
            {
                rotationVal = Mathf.Lerp(0f, -90f, Time.deltaTime);
                myTransform.Rotate(0, rotationVal, 0);
                temp += rotationVal;
            }

        }
    }

    void Turning()
    {
        Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit wallHit;
       
        if(Physics.Raycast(camRay, out wallHit, camRayLength, wallMask))
        {
            Vector3 playerToMouse = wallHit.point - transform.position;
            playerToMouse.x = 0f;
            playerToMouse.z = 0f;

            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
            obj.MoveRotation(newRotation);
        }


    }
}

You need to use KeyCode when getting a key. Use your code complete options when writing code and it will help a lot.

if(Input.GetKeyDown(KeyCode.Left){
}

Thanks for the response, I’ve added the KeyCode to the script, unfortunately this has thrown up some errors.

void Update()
    {
        if (canMove)
        {
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            }
            turnLeft = true;
                //TurnLeft();
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                turnRight = true;
                //TurnRight();
            }

It specifically says ‘Feature Tuples is not available in C# 4’
‘Input.GetKeyDown does not exist in the current context’
‘GetKeyDown does not exist in the current context’

So help, fixing those will be appreciated.

The brace here is backwards ‘}’ should be ‘{’

if (Input.GetKeyDown(KeyCode.LeftArrow))
            }

That fixed it, thanks.

Though the Vehicle still spins on the spot and inverts its controls, so I still don’t know how to fix that.

I would recommend using the debugger to help you solve these problems.

Also, I don’t know if you have already seen the unity tutorial on controlling a tank. Maybe that could provide you with some helpful insights as to how this can be achieved?