- Home /
Character moving up/down & left/right while constantly going forward in Z
I'm attempting to create a 'flying' character that the player can move up or down on the y axis and left or right on the x axis, while constantly moving forward in the z axis.
The problem I'm seeing is that the player gets 'stuck' for lack of a better term on the x axis. The model will move a few pixels to the right, for example, then stop while still being able to move over to the left without issue. What I don't understand is why the player moving on the y axis isn't doing the same thing.
WEB PLAYER http://acjcllc.com/unity/WebPlayer/WebPlayer.html
This is the script I'm using:
var speed:float = 10.0;
private var thisTranform:Transform; private var thisCharacter:CharacterController;
function Start () { thisTranform = GetComponent(Transform); thisCharacter = GetComponent(CharacterController); }
function Update() { dir = new Vector3( Input.GetAxis("Horizontal") Time.deltaTime speed, Input.GetAxis("Vertical") Time.deltaTime speed, 0.25 ); Debug.Log(dir); thisCharacter.Move(dir); }
NOTE: The player is controlled with a Character Controller, not a Rigidbody. I've tried both FixedUpdate and Update without any change in behavior.
Any idea of why this is happening? Or, if there is a better way to do it, how? Links to tutorials / explanations appreciated.
Thanks!
Answer by Mike 3 · Feb 27, 2011 at 06:45 PM
Is it possible that you have attached a cube collider to the character controller?
If you have both on, it's likely that there will be collision between the two, screwing things up somewhat
that was exactly it - I had a box collider on the cube, which was a child of the game object with the script. Thanks!