- Home /
Moving platform affects movement
Hello,
I have moving platforms in my game. When the marble rolls on the platform, then it will be the child of the platform. It is working fine untill I start to move while the platform is moving. Then the movement of the marble is acting strange.
The marble is controlled by force, so it has rigidbody, and moves with FixedUpdate. However, the platform is moved by it's transform, and uses Update. I think this is causing the problem. I have tried to use FixedUpdate on the platform aswell, but then the platform is moving strangely.
Here are the code of the platform:
The triggerer of the platform: var liftMain : Transform; var player : Transform;
function OnTriggerEnter (other : Collider)
{
if (other.tag == "Player")
{
player.transform.parent = liftMain.transform;
}
}
function OnTriggerExit (other : Collider)
{
if (other.tag == "Player")
{
player.transform.parent = null;
}
}
The movement script of the platform: var up : boolean = false; var down : boolean = false;
function Start ()
{
Test();
}
function Update()
{
if (up)
{
transform.Translate(Vector3.up * 0.1 * Time.deltaTime);
}
if (down)
{
transform.Translate(Vector3.down * 0.1 * Time.deltaTime);
}
}
function Test()
{
yield WaitForSeconds(5);
up = true;
yield WaitForSeconds(5);
up = false;
yield WaitForSeconds(1);
down = true;
yield WaitForSeconds(5);
down = false;
}
Answer by Dreeka · Aug 03, 2011 at 10:28 AM
Giving a kinematic rigidbody component to the platform, and changing the Update to FixedUpdate solved the problem.