- Home /
Question by
PaxNemesis · Sep 15, 2011 at 10:54 AM ·
charactercontrollermove
Moving objects diagonally with the CharacterController.Move command
Hello there. I've been working on an AI that should be able to move diagonally to a position without having the CharacterController to look at it. Meaning GameObject.transform.forward should not need to point in the direction of the desired location.
void MoveObjectReversed(AIOwnerGameObject owner, Vector3 toPosition)
{
Vector3 moveDirection = Vector3.zero;
// Direction to move.
// Owner - gameObject with some more features
// owner.movementSpeed - float
// IgnoreY(Vector3) - removes the y value
moveDirection = (IgnoreY(toPosition - owner.position)).normalized * owner.movementSpeed;
// Apply gravity
// owner.gravity - Vector3
moveDirection += owner.gravity;
// Move the controller
owner.controller.Move(moveDirection * Time.deltaTime);
}
Edit: I discovered the problem. It have nothing to do with this code. It's working as intended :)
Comment
Answer by Piflik · Sep 15, 2011 at 11:59 AM
Try:
moveDirection = (IgnoreY(toPosition - owner.position)).normalized * owner.movementSpeed;
Thanks for the input, but sadly it didn't change the result.
The object isn't moving at all, just standing there looking stupid :P