i have problem with circle moving platform
i have Circle, the circle rotate around itself and move right and left
when player jump on the circle, the player be child of the Circle
it works fine, but sometime doesn’t (not be a child of a circle)
Circle attached with PlatformController
Player attached with PlayerController
PlatformController.cs
public class PlatformController : MonoBehaviour {
public int rotateSpeed;
public int moveSpeed;
public bool isMoving;
void Start () {
rotateSpeed = Random.Range (1,7);
moveSpeed = Random.Range (1,7);
}
void FixedUpdate () {
transform.Rotate (0,0,1);
if (isMoving) {
transform.Translate (moveSpeed * Time.deltaTime ,0,0 , Space.World);
}
}
void OnTriggerEnter2D (Collider2D other) {
if (other.gameObject.tag == "rightBorder") {
moveSpeed = -moveSpeed;
}
if (other.gameObject.tag == "leftBorder") {
moveSpeed = Mathf.Abs (moveSpeed);
}
}
}
Player Controller Script
public class PlayerController : MonoBehaviour {
Rigidbody2D rb;
public float jumpSpeed;
public bool touchGround;
// Use this for initialization
void Start () {
rb = GetComponent();
}
// Update is called once per frame
void Update () {
Jump ();
}
public void Jump () {
if (Input.GetKeyDown (KeyCode.Space)) {
if (touchGround) {
rb.constraints = RigidbodyConstraints2D.None;
rb.velocity = new Vector2 (0, jumpSpeed);
}
}
}
void OnCollisionEnter2D (Collision2D other) {
if (other.gameObject.tag == "ground") {
touchGround = true;
this.transform.parent = other.gameObject.transform;
rb.constraints = RigidbodyConstraints2D.FreezePositionY;
}
}
void OnCollisionExit2D (Collision2D other) {
if (other.gameObject.tag == "ground") {
touchGround = false;
this.transform.parent = null;
rb.constraints = RigidbodyConstraints2D.None;
}
}
}
i need to know why sometime the player in the game can’t be child of the circle ?
Thanks , sorry for my english