- Home /
CharacterController moves only sometimes
I have this setup where one character moves according to another characters Z position. I got everything going, but, for some reason it only works when it moves negative on the z axis positive, does not work at all?
I have cut down the C# script a bit, and made sure this gives me the same non-working result.
In the example here, the "else if" that prints "Less" will work on the y axis, but not on the z axis (Witch is the axis i need it to move along) Am I being dumb, or is there something wrong with my code?
Thanks for taking your time to read my problem.
using UnityEngine; using System.Collections;
public class NewBoss1Script : MonoBehaviour {
private GameObject viking1;
private CharacterController controller;
// Use this for initialization
void Start () {
viking1 = GameObject.Find("Viking1");
controller = (CharacterController) GetComponent<CharacterController>();
this.transform.Rotate(new Vector3(0, 90, 0));
}
// Update is called once per frame
void Update () {
if (controller.transform.position.z > viking1.transform.position.z)
{
controller.Move(new Vector3(0,-2,-1) * Time.deltaTime);
print ("More");
}
else if (controller.transform.position.z < viking1.transform.position.z)
{
controller.Move(new Vector3(0,-2,1) * Time.deltaTime);
print ("Less");
}
}
}
Answer by Tabu · Dec 07, 2010 at 09:53 AM
Ok, it totally does not make sence. I have tried all sorts of different things. Now after alot of "head scratching" and wondering, I finally tried to create the gameoject from scratch, copying the script bit by bit into a new file.. .lo and behold, it works? The old object does not work, new one does... so Im thinking something in the old object has broken or something? Also exported new animations, wich only works for the new gameObject, but not the old one?
Is there any way to close a topic like this?
EDIT: Sollution was to remove the meshcolliders I had attached to my character, after that it worked. I now use Capsule colliders instead.
Answer by Justin Warner · Dec 06, 2010 at 03:40 PM
It could have the local axis flipped... so it MIGHT be the y-axis, but you see z-axis... So check the local (if your in world) or check the world (if your in local) and see if it flips...
All the best!
yea, i had that thought also :) But unfortunately this did not change anything :( I think its some sort of bug in my GameObject that causes this! Thanks for you time anyways mate :)
Your answer
Follow this Question
Related Questions
Moving AI away or towards player not working correctly. 1 Answer
How can I convert LOCAL transform.forward to WORLD Vector3? 2 Answers
Very Simple Left and Right Movement Script [OR] disable dravity on CharacterController? 2 Answers
Move in the direction its facing C# 2 Answers
Character Controller Won't SimpleMove() 0 Answers