Hi, for an unknown reason when my CharacterController moves over a small ledge, then moves back it gets stuck? Any ideas on why this happens? It is so annoying! I’ve tried changing my settings to the defaults, and lots of different sorts of numbers but there is no luck! THIS IS A LINK TO A WEBPLAYER(IN FRONT OF YOU IS THE JUMP)
My Character controller stats are as follows(ATM):
Slope Limit: 45
Step Offset: 0.03
Skin Width: 0.08
Min Move distance: 0
Center: (0,0,0)
Radius: 0.5
Height: 1.1
The little jump(like a cliff) is 0.5units tall and 1.01 along the x axis. When the Character Controller moves over the jump then can continue to move fine, but if the character attempts to move back and runs into the side of the jump that is not sloped then they get stuck, but they can get out if they just randomly press the directional keys or WASD. The strangest thing of all is when this happens some strange occurrences happen were the transforms position fluctuates ever so slightly, and if I manually set in the editor the position it should be then it can move freely out and about? (Like if it is meant to be at 0,0,5, then it is actually fluctuating slight at around 0,0,4.9999995)
Before you see the code that is moving the CharacterController, its important to note that by removing the code that places the character automatically to the nearest multiple of 0.125 it will still occur.
This is the code that moves the player:
public class IncrementalMovement : MonoBehaviour {
public CharacterController cc;
private bool moving = false;
private float to;
public float speed;
public float gravity;
public bool pause;
private Transform cctrans;
void Start(){
cctrans = cc.transform;
}
void Update(){
cc.Move(new Vector3(0,-gravity,0));
}
public void MoveUp (){
if(!moving){
StartCoroutine(MoveUp2(Round(cc.transform.position.z + 0.125f,0.125f)));
}
}
public void MoveDown (){
if(!moving){
StartCoroutine(MoveDown2(Round(cc.transform.position.z - 0.125f,0.125f)));
}
}
public void MoveRight (){
if(!moving){
StartCoroutine(MoveRight2(Round(cc.transform.position.x + 0.125f,0.125f)));
}
}
public void MoveLeft (){
if(!moving){
StartCoroutine(MoveLeft2(Round(cc.transform.position.x - 0.125f,0.125f)));
}
}
public void ConfirmPosition(){
cctrans.position = new Vector3(Round(cc.transform.position.x,0.125f),cctrans.position.y,Round(cc.transform.position.z,0.125f));
}
private IEnumerator MoveUp2 (float to){
moving = true;
while(true){
cc.Move(new Vector3(0,0,speed * Time.deltaTime));
if (cctrans.position.z >= to){
break;
}
yield return null;
}
moving = false;
//cctrans.position = new Vector3(cctrans.position.x,cctrans.position.y,to);
}
private IEnumerator MoveDown2 (float to){
moving = true;
while(true){
cc.Move(new Vector3(0,0,-speed * Time.deltaTime));
if (cctrans.position.z <= to){
break;
}
yield return null;
}
moving = false;
cctrans.position = new Vector3(cctrans.position.x,cctrans.position.y,to);
}
private IEnumerator MoveRight2 (float to){
moving = true;
while(true){
cc.Move(new Vector3(speed * Time.deltaTime,0,0));
if (cctrans.position.x >= to){
break;
}
yield return null;
}
moving = false;
cctrans.position = new Vector3(to,cctrans.position.y,cctrans.position.z);
}
private IEnumerator MoveLeft2 (float to){
moving = true;
while(true){
cc.Move(new Vector3(-speed * Time.deltaTime,0,0));
if (cctrans.position.x <= to){
break;
}
yield return null;
}
moving = false;
//cctrans.position = new Vector3(to,cctrans.position.y,cctrans.position.z);
}
float Round(float numToRound, float multiple){
if(numToRound<0){
multiple = multiple*(-1);
}
if(multiple == 0){
return numToRound;
}
float remainder = numToRound % multiple;
if (remainder == 0){
return numToRound;
}
return numToRound + multiple - remainder;
}
}
Any ideas on how to stop this would be great