Character stuck when parent moving.

Hey there,

I’m developing a 3D platformer game and one of the key aspects is moving platforms. I’ve wrote a script for a platform to move to a certain point once activated. I want the player to be able to move with this platform.

Basically I have a script on the platform that moves it and another script that detects collision with the player then if the player has collided then child the player to the platform.

Upon collision, the player becomes parented and can walk about the platform and jump off. The player then activates the platform by pressing a key, the platform starts moving using a Lerp to a final position but as soon as the platform starts moving, the player becomes stuck and can no longer move or jump off the platform even when the platform has reached its destination.

When the platform is moving, the player is still parented but all user controls are lost, after doing some commenting and debug log statements, the problem lies with the Lerp statements in the moving platform code. If I comment them out then the player can move freely as a child but the platform no longer moves.

Here is the code for the move platform script:

	void Update () {
		
		//Check if the key has been pressed, it will be true if it has
		moveStarted = this.GetComponent<GuiTrigger>().keyPressed;
		
		//Have we started moving?
		if(moveStarted){
			lerpPos += Time.deltaTime/platSpeed;
			transform.localPosition = Vector3.Lerp(intPos, endPos, lerpPos);
			
			if(rotateObject){
				transform.localEulerAngles = Vector3.Lerp(intRot, endRot, lerpPos);
			}
		}
	}

After further testing, the problem doesn’t lie in the movement well at least I don’t think so as I have tried Transform.Translate statements and the same problem still occurs.

What I’m stumped at though is the player is parented to the moving platform while it is still (noticeable by the hierarchy) and can move around/jump off but as soon as the platform starts moving, the player is still parented but all movement is lost. There’s no noticeable change in the hierarchy, no change in any player settings, no code to turn any controls off.

I don’t want to start uploading lots of code on here to put all you off reading it, is there any common reason why the character would get jammed?

The character controller has a small capsule collider at it’s feet (isTrigger on) and the player also has a rigidBody with gravity and kinematic enabled. The platform has a rigidbody with gravity and isKinematic enabled, the platform also has a box collider covering all of it (isTrigger is off).

	void OnTriggerEnter(Collider other){
		//Check if the object we have collided with is the player
		if(other.gameObject.tag == "Player"){
			//Make the player a child of the platform
			//so the movement is relative
			counter++;
			other.transform.parent = transform;
			Debug.Log("Parented");
		}
	}
	
	void OnTriggerExit(Collider other){
		if(other.gameObject.tag == "Player"){
			//Remove the player as a child
			other.transform.parent = null;
			Debug.Log("Unparented");
		}
	}

Any help would be appreciated.