I’ve been working on a project using the NGUI system for the 2D. Since there is no built-in collision detection for the images, I had to make one myself, and it is accurate in the center of the screen, but nearer the end, it starts getting off. The camera never moves and the wall itself doesn’t move, only the character. Can someone help me? Here is my collision code-
public int[] checkForCollision(){
decimal cX = Character.x;
decimal cY = Character.y;
decimal cW = (decimal) Character.person.transform.lossyScale.x;
decimal cH = (decimal) Character.person.transform.lossyScale.y;
decimal cU = cY;
decimal cD = decimal.Subtract(cY, cH);
decimal wU = y;// + (height / 2);
decimal wD = decimal.Subtract(y, height);
int[] returnList = new int[3];
if (cD < wU cU > wU){
Debug.Log("Bottom of Character collide with top of wall!");
returnList[0] = 1;
returnList[1] = -1;
} else if (cU > wD cD < wD){
Debug.Log("Top of Character collide with bottom of wall!");
returnList[0] = 1;
returnList[1] = 1;
}else {
returnList[0] = 0;
}
return returnList;
}