Player Movement Goes Crazy When Hit On Side Of Moving Platform
THIS IS ON PLAYER CONTROLLER SCRIPT void FixedUpdate() { if(!GameController.gameOver) {
//let the player to move the ball
touchControl();
//set offset for ball
transform.position = new Vector3(transform.position.x, 0.5f, transform.position.z);
//prevent ball from exiting the view (downside)
if(transform.position.z < -5)
transform.position = new Vector3(transform.position.x, transform.position.y, -5.0f);
//prevent ball from exiting the view (Upside)
if(transform.position.z > 4f)
transform.position = new Vector3(transform.position.x, transform.position.y, 4f);
//left/right movement limiters
if(transform.position.x > 3.1f)
transform.position = new Vector3(3.1f, transform.position.y, transform.position.z);
if(transform.position.x < -3.1)
transform.position = new Vector3(-3.1f, transform.position.y, transform.position.z);
}
}
// Control ball's position
void touchControl(){
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate(Vector3.right * speedBall * Time.deltaTime);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate(Vector3.left * speedBall * Time.deltaTime);
}
}
///***********************************************************************
******THIS IS ON GAME CONTROLLER SCRIPT******
/// Clone Maze item based on a simple chance factor
///***********************************************************************
void cloneMaze() {
createMaze = false;
startPoint = new Vector3( Random.Range(-1.0f, 1.0f) , 0.5f, -7);
Instantiate(maze[Random.Range(0, maze.Length)], startPoint, Quaternion.Euler( new Vector3(0, 0, 0)));
StartCoroutine(reactiveMazeCreation());
}
******THIS IS ON PLATFORM MOVER******
[Range(1.5f, 2.5f)]
public float speed = 2.0f; //movement speed
private float destroyThreshold = 10.0f; //destory passed mazes to free up the memory
void FixedUpdate() {
//Scroll down the maze objects
transform.position += new Vector3(0, 0, Time.deltaTime * GameController.moveSpeed * speed);
//Destroy it if it's out of screen view
if (transform.position.z > destroyThreshold)
Destroy(gameObject);
}
}
The platform(maze) will move from downwards to up and increase the speed every 10 second.
When my player(a 3D sphere) move along the edge of the platform(attached with box collider), especially when touch the side or fall on the edge of the platform, it will start to move on its own and the key button wont work ,example when i press right,the ball will move up or opposite direction or float and vice versa.
Did i wrote wrong on the script? or i missed something?
I want my player to move smooth without going crazy throughout the whole speed.
Also,i have no problem when moving left and right on the platform flat surface,only when hit the side and other platform side ,it goes crazy.
Sorry for my bad English,i'm not a native speaker.
Here is additional info:
left is platform(maze child) inscpector, right is sphere inspector. THANK YOU!