- Home /
Player won't stick to moving cube
Hello, I am making a parkour game, i have moving blocks that the player has to jump on and ride. When the player does jump on the block he just slides right off, the block is using an animation to move. I've tried to look up some answers to this problem but my player object (Known as FPSController in my script) just keeps sliding off. Here's the code that was supposed to help:
public class StickToBlock : MonoBehaviour {
public GameObject FPSController;
// Use this for initialization
void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == "Cube") {
FPSController.transform.parent = other.gameObject.transform;
}
}
// Update is called once per frame
void OnTriggerExit (Collider other) {
FPSController.transform.parent = null;
}
}
Answer by JxWolfe · Jun 16, 2017 at 05:26 PM
I would turn the animation into a script that moves from one vector3 to another. And then change the last 3 lines of code to:
void OnTriggerExit(Collider other)
{
if(other.tag == cube)
{
FPSController.transform.parent =null;
}
}
and make sure there is a Collider under the player that has IsTrigger set to true Add the script to the FPSController Object
not sure if you need to change the movement to a script, it may just be the trigger not existing or the trigger leaving somethings Collider that's not the platform
Answer by Killerbro389 · Jun 16, 2017 at 05:55 PM
yeah if you want an object to to collide with other physical objects, as in have a player stand on it, then use a script instead of an animation.