Space Ship Code

Hi, Today, I wanted to write a code for space ships, the player must push the forward arrow to move the ship and push space for afterburn…
But nothing happes, there are only some error messages and I don’t know what to do now… :?

var speed = 6.0;
var jumpSpeed = 12.0;

private var moveDirection = Vector3.zero;

function FixedUpdate() {

		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		if (Input.GetButton ("Jump")) {
			moveDirection.z = jumpSpeed;
		}

	// Apply gravity
	moveDirection.y = Time.deltaTime;
	
	// Move the controller
	var flags = transform.Translate(moveDirection * Time.deltaTime);
}

moveDirection = new Vector3(Input.GetAxis("Vertical"));

Here’s at least part of the problem: “Vector3” requires values for all three axis, so something like this might work:

moveDirection = new Vector3(Input.GetAxis("Vertical"), y, z));

Haven’t tried this but it should at least get you started.

try this:

var speed = 6.0;
var jumpSpeed = 12.0;

private var moveDirection = Vector3.zero;

function FixedUpdate() {

// We are grounded, so recalculate movedirection directly from axes

// Vector3 requires 3 arguments
moveDirection = new Vector3(0,Input.GetAxis(“Vertical”),0);

moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;

if (Input.GetButton (“Jump”)) {
moveDirection.z = jumpSpeed;
}

// Apply gravity
moveDirection.y = Time.deltaTime;

// Move the controller

//transform.Translate doesn’t return a value
transform.Translate(moveDirection * Time.deltaTime);
}

Thanks guys, that’s working great! :slight_smile: