Page 1 of 1

Can't show input direction?

Posted: Wed Aug 08, 2012 4:00 am
by Callan S.
I found some code for controlling a platforming character. I'd like to know what direction was last pressed, so I can change the graphic shown on the cube used for the platforming dude. But I can't figure out how to access it to even show it!

Code: Select all

// borrowed from:

// http://answers.unity3d.com/questions/20261/how-can-i-make-double-jump-need-help.html



var WalkSpeed = 6.0;

var RunSpeed = 6.0;

var jumpSpeed = 8.0;

var gravity = 20.0;

var direction=0;



private var moveDirection = Vector3.zero;

private var grounded : boolean = false;



function FixedUpdate() {



	if (grounded) {

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

		// moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

		moveDirection = new Vector3(Input.GetAxis("Horizontal")*-1,0,0);

		moveDirection = transform.TransformDirection(moveDirection);

		var mySpeed = WalkSpeed;



		/*

		if (Input.GetKey("left shift")) {

			mySpeed = RunSpeed;

		}

		*/

		moveDirection *= mySpeed;

		

		if (Input.GetButton ("Jump")) {

			moveDirection.y = jumpSpeed;

		}

	}



	// Apply gravity

	moveDirection.y -= gravity * Time.deltaTime;

	

	// Move the controller

	var controller : CharacterController = GetComponent(CharacterController);

	var flags = controller.Move(moveDirection * Time.deltaTime);

	grounded = (flags & CollisionFlags.CollidedBelow) != 0;



direction=Input.GetAxis("Horizontal")*-1;

GameObject.Find ("GUI Text").guiText.text="wow!: ".direction;

//.moveDirection;

}



@script RequireComponent(CharacterController)

// character controller heigh = 0.85

// radius = 0.4
More specifically it's probably a value in this line I want to show in GUI Text/be able to read

Code: Select all

moveDirection = new Vector3(Input.GetAxis("Horizontal")*-1,0,0);
But I don't seem to be able to do it?

Re: Can't show input direction?

Posted: Sat Aug 11, 2012 1:07 am
by SpiritWebb
A 2d platformer?

If so, here is a link for a tutorial on how to do a Mario clone, and this could help you:
http://walkerboystudio.com/html/unity_course_lab_4.html

Re: Can't show input direction?

Posted: Sat Aug 11, 2012 2:14 am
by Callan S.
Wow, thanks for the link, Spirit! I assure you I googled quite a few times and never found something like this!

Re: Can't show input direction?

Posted: Sat Aug 11, 2012 2:48 am
by SpiritWebb
No problem, glad I could help. If you notice, they have quite a bit of tutorials on there! :)

Re: Can't show input direction?

Posted: Sat Aug 11, 2012 11:13 am
by OldRod
I started through the Walker Boys tutorials last year. They are pretty good, at least the ones I went through.

At the time, the Mario tutorial was locked until you completed some earlier ones. Looks like they removed that restriction. Nice! :)

Re: Can't show input direction?

Posted: Sat Aug 11, 2012 11:28 am
by Callan S.
Heh, and yet I've decided to start with the clicking game tutorial anyway!

Re: Can't show input direction?

Posted: Thu Aug 23, 2012 8:59 pm
by SpiritWebb
:lol: