space vessel //CarController1.js

Hi guys, I’m new to Unity and not a programmer!

I just found a JS script posted by jeffmorris and thought to give it a try with my spaceship project. I attach the script to my space vessel but am getting an error “Input Axis throttle is not setup” The console prompts me to Edit - Project Settings - Input, but I don’t know how to use the Input Manager…Is it a quick fix?

I believe that script is what I am looking for so I

Thanks!

you just need to setup a new axis in the input manager called “throttle” or whatever the script is calling it (case and spelling is important)

In the inputmanager increase the size of the Axes array by one.
The last entry should be duplicated now. Set the name to throttle in your case and set the keys you like to correspond to that input axis.

Here you can get further explanation of what the different fields are for:

Hi guys! thank you for responding so fast! I think I’m getting there…now it gives me another error however,

“Array index is out of range” at string “109” Does anyone understand what that means?

I’m guessing you having dragged the wheels into the scripts “wheels” slot in the inspector, there has to be all 4 of them in that array for that code to work (hardcoded array access without checking the array’s size… :()

109 is the line number in your script that is going wrong… index out of range means you asked for an array member outside the size of the array. I.e. give me the 3rd member when there is only one element in the array.

Well my space vessel doesn’t have wheels… :frowning:

Can this script still work?

given that that script is mostly about dealing with wheelcolliders, if you don’t have any wheel… probably not.

you’ve not really explained what it is you are trying to do, just asked for explanations as to what problems your implementation of the script is having, so its hard to say really.

Well, using the code below (by Grim Grin Gaming Character Controller tutorial) I am able to get half of the job done!!!

Now I need two things:

  1. To be able to control and adjust gravity (with a slider just like MoveSpeed; and RotationSpeed)

  2. To make the vessel stick to the track when there is road below it (I read this can be achieved with Raycast but its too advanced for me…)

Is it possible for someone to modify the code below so that it incorporates the control and adjustment of gravity for my vessel?

I attached an image to illustrate my situation.
Many thanks!

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))]

public class SpaceNavigation : MonoBehaviour
   
{
    public float MoveSpeed;
    public float RotationSpeed;
    CharacterController cc;
   
    // Use this for initialization
    void Start ()
       
    {
        cc = GetComponent<CharacterController>();
    }
    // Update is called once per frame
    void Update () {
       
        Vector3 foward = Input.GetAxis("Vertical") * transform.TransformDirection(Vector3.forward) * MoveSpeed;
        transform.Rotate(new Vector3(0,Input.GetAxis("Horizontal") * RotationSpeed * Time.deltaTime,0));
        cc.Move(foward * Time.deltaTime);
        cc.SimpleMove(Physics.gravity);

I updated my code based on this tutorial (#3.3 Jump and Gravity - Unity C# Basic Code)!

However gravity doesn’t seem to affect the vessel :frowning:

Can anyone point out the mistake on my code?

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))]

public class SpaceNavigation : MonoBehaviour
   
{
    public float MoveSpeed;
    public float RotationSpeed;
    public float gravity = 9.8f;

    CharacterController cc;
    Vector3 currentMovement;

    // Use this for initialization
    void Start ()
       
    {
        cc = GetComponent<CharacterController>();
    }
    // Update is called once per frame
    void Update () {
       
        Vector3 foward = Input.GetAxis("Vertical") * transform.TransformDirection(Vector3.forward) * MoveSpeed;
        transform.Rotate(new Vector3(0,Input.GetAxis("Horizontal") * RotationSpeed * Time.deltaTime,0));
        cc.Move(foward * Time.deltaTime);
       

        currentMovement = new Vector3(0, currentMovement.y, Input.GetAxis("Vertical") * MoveSpeed);
        currentMovement = transform.rotation * currentMovement;


        if (!cc.isGrounded)
            currentMovement -= new Vector3 (0, gravity * Time.deltaTime, 0);

        //cc.SimpleMove(Physics.gravity);

    }
}