Hello there. I’ll be brief. It’s a top-down 2D game, working on the X and Z axis, with Y being the “jump” or “flying” axis. Using CharacterController.Move, with the following code, the character moves properly on the X axis, however, does not move on the Z axis, but the instead Y axis:
moveDirection = new Vector3(-1, 0, 1);
charController.Move(moveDirection * Time.deltaTime * moveSpeed);
Note: this code is meant to move you diagonally northwest. Swapping the Y and Z for the vector3 - (-1, 1, 0) - does doesn’t change anything. Forcing moveDirection.y = 0 doesn’t stop the upward ascension, so I’m quite confused.
Any tips?
I see nothing in that code that would cause movement along the y-axis. Maybe Physics.gravity or some other force is affecting it?
Hence my confusion, haha. I have gravity disabled via the project settings, though the Y is definitely increasing rather than decreasing, and only while moving in the northwest direction. I’m not sure if it matters either but I’m indeed using a charactercontroller and not a rigidbody. The scene is pretty bare bones, with a “floor” and my player object only, the player movement being the only moving objects/scripts working.
I noticed interesting behavior. I have an object with a collider as a child of my Player object, which contains the movement script and the character controller. Disabling it actually stops this flying from happening (which is unfortunate since I really need to detect collisions). However, I can’t get my object to move on the Z axis using CharacterController.Move, regardless of the collider or not.
Since I’m sure someone will ask to post my code, here it is:
using System;
using UnityEngine;
public class PlayerControls : MonoBehaviour
{
public float moveSpeed = 5.0f;
private CharacterController charController;
Vector2 moveDirection;
void Start () { charController = GetComponent<CharacterController>(); }
void Update () {
bool keyboardUp = Input.GetKey(KeyCode.UpArrow);
bool keyboardDown = Input.GetKey(KeyCode.DownArrow);
bool keyboardLeft = Input.GetKey(KeyCode.LeftArrow);
bool keyboardRight = Input.GetKey(KeyCode.RightArrow);
if (keyboardUp keyboardLeft) {
moveDirection = new Vector3(-1, 0, 1);
charController.Move(moveDirection * Time.deltaTime * moveSpeed);
}
}
}
EDIT:
I noticed why it wasn’t moving on the Z axis once I posted my code… moveDirection I made a Vector2 on accident.
Now I guess this is exclusively about the flying issue when the Character Controller and collider. Any ideas?
Ha, the Vector2 is a good catch!
Is the child collider and the CharacterCollider intersecting/overlapping? Does the child collider have a rigidbody? Can you set the child collider’s isTrigger to true and listen for trigger events instead?
I know that two separate rigidbody colliders overlapping will cause them to be forced apart, possibly sending one or both flying at high speeds. I’m wondering if you are experiencing something like that with the child collider and character controller overlapping.
EDIT: If it really is this, another thing you can try is putting the child collider on a different layer than the character controller, and in the Physics settings you can have them ignore each other.
Yup, you were right! They weren’t exactly overlapping, they were mathematically touching perfectly, but it was enough to cause the strange physics effect. I wasn’t too concerned about their physical vertical position in the world since it’s isometric view, so I just moved it up a smidge and everything’s good.
Thank you very much, Garth!
EDIT: I went ahead and backed your game on Kickstarter. Thanks again!
Sweet, thanks for the support! Keep having fun developing games! =)
Hey thanks, you too!
The Adventures of Pip definitely looks like a game I would be interested in playing. 
Keep up the good work!