Character Controller Fly

Hello Again!

So, I’ve got this character, its got the character controller script attached, as well as my own movement script(FPS style without the fps prefab). Now I’m trying to create a fly spell. Which obviously flips my character controller on its hindquarters.

Enter: my problem. The character controller apears to restrict Yaxis movement on the character. In order for the movement script to handle properly, I need the movement to be based on a y axis as well. Aim down, push forward, fly down. Simple see? I could be wrong but so far I’ve tried the following.

Specifically attaching a mouse look script with the Y section enabled.

Checking to see any of the objects y-rotation is constricted.

adding another object to the character to see if it rotates independantly of the CC. Which is doesn’t.

I’ll include my movement script just in case >.0

//Speed Variable unstable above 25

var speed = 6.0;

var airspeed = 5.0;

var jumpSpeed = 8.0;

var gravity = 20.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 = transform.TransformDirection(moveDirection);

		moveDirection *= speed;			

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

			moveDirection.y = jumpSpeed;

			}

		}

		else {

		

		//Preserving fall value

		var fall = moveDirection.y;

		

		

		var NewmoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

		NewmoveDirection = transform.TransformDirection(NewmoveDirection);

		moveDirection = moveDirection + ((NewmoveDirection * airspeed) * Time.deltaTime);

		

		

		

		//Replacing Y movement value to original fall

		moveDirection.y = fall;

		}



	// Apply gravity

	moveDirection.y -= gravity * Time.deltaTime;

	

	// restrict to speed and Move the controller

	moveDirection.x = Mathf.Clamp(moveDirection.x, -speed, speed);

	moveDirection.y = Mathf.Clamp(moveDirection.y, -speed, speed);

	moveDirection.z = Mathf.Clamp(moveDirection.z, -speed, speed);

	var controller : CharacterController = GetComponent(CharacterController);

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

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

    }
    
    
    
    @script RequireComponent(CharacterController)

Now that that’s out of the way. Specifically my questions are.

Does the character controller stop y axis rotation?

If so, is there a handle to prevent this?

If not can you see a way to fix this?

Assuming its my programming, should I create a entirely seprate code handling the instance of gravity = 0 and onground.false?

After extensive debugging I determined that the Y axis rotation was not prevented like I originally thought.

The issue actually lies in the mouse rotation scripts… Mouse look I believe most people call it. Apparently there is a reason they have you split the mouseX and mousey portions onto separate objects.

Somehow they interact and completely screw it up when you place both of them on a single object. I’ll now be hunting for a X and Y Mouse look script to see if it solves the issue. (Note: the reason I’m not writing my own on this one is because I still don’t understand quaternions well enough to tinker properly.)

In case anyone is following this thread I’ll keeo you posted on the results.