This problem is a bit hard to explain and maybe confusing, but I will try my best to explain it. I use iTween for the movement of the cubes in my game. When the player collides with the activating cube / is a child of the activating cube, the cube starts moving. However, when my player jumps on a moving cube, the cube will stop moving for a couple of seconds and I don't know why. It has something to do with iTween.MoveTo, because this doesn't occurs when using iTween.MoveBy (like I did at Cube (1) 2 in the script below), but I have to use MoveTo.
Script:
using UnityEngine;
using System.Collections;
public class CubeMovement: MonoBehaviour
{
public int startX;
public float startTime;
public int pingPongX;
public float pingPongTime;
private bool started;
public GameObject playerObj;
public float originalY;
public float fallDownTime = 1912;
public GameObject activatingCube;
void Awake()
{
pingPongTime = (startTime / (Mathf.Abs(gameObject.transform.position.x - startX))) * (startX - pingPongX);
}
void Update()
{
Player player = playerObj.GetComponent<Player> ();
//All blocks start moving after 1 click
//if (player.clicks == 1 && started == false)
//{
// StartX ();
//}
Debug.Log(started);
//This block starts moving after player collides with activatingCube
if (started == false && playerObj.transform.parent == activatingCube.transform)
{
StartX ();
started = true;
Debug.Log ("Going to start");
}
}
void StartX()
{
started = true;
Debug.Log ("Started");
if (gameObject.transform.name == "Cube (1)2") //omdat dit blokje hetzelfde is als activating cube werkte het alleen met moveby
{
iTween.MoveBy (gameObject, iTween.Hash ("x", startX, "time", startTime, "easeType", "easeInOutSine", "loopType", "none", "delay", 0));
}
StartCoroutine(FallDown(fallDownTime));
StartCoroutine (StartPingPong (startTime));
if (gameObject.transform.name != "Cube (1)2")
{
iTween.MoveTo (gameObject, iTween.Hash ("x", startX, "time", startTime, "easeType", "easeInOutSine", "loopType", "none", "delay", 0));
}
}
IEnumerator StartPingPong(float startTime)
{
yield return new WaitForSeconds (startTime);
iTween.MoveTo(gameObject, iTween.Hash("x", pingPongX, "time", pingPongTime, "easeType", "easeInOutSine", "loopType", "pingPong", "delay", 0));
}
}
How it looks like:
Btw when the player collides with a cube, it will become a child of it, until it jumps off the cube. The cube stops moving when the player becomes a child of it and after a couple of seconds it starts moving again, why?