- Home /
Character Control stuck in parent movement.
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.
When the platform is moving, the player is still parented but all user controls are lost, after doing some commented 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 they key has been pressed, it will be true if it has
moveStarted = this.GetComponent().keyPressed;
//Have we started moving?
if(moveStarted){
lerpPos += Time.deltaTime/platSpeed;
transform.position = Vector3.Lerp(intPos, endPos, lerpPos);
if(rotateObject){
transform.eulerAngles = Vector3.Lerp(intRot, endRot, lerpPos);
}
}
}
Any help is appreciated.