I have animated moving platform.I need to jump on it and move together with it near other platform.As mario game.But first person controler prefab cant stay on there.Once I’m on it , I fell from that platform I cant move with it together. how to fix it?
Head on over to UnityAnswers: there are a slew of solutions and examples:
The first time i wrote a platform code was a lot of fun
The mothod i used was to use a trigger from a box collider just on top of the platform. and OntriggerEnter make the player a child of the platform and push the player up just a little while in OnTriggerStay. and it works pretty good with just a little adjustment of the box collider ![]()
var other: GameObject;//Here the function checks for the Other collider
////////////////////////////////////////////////////////////////////////
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag == "Player") {
//Make the player the child of the parent
other.gameObject.transform.parent=gameObject.transform;
}
}
/////////////////////////////////////////////////////////////////////////
function OnTriggerStay(){
for (var child : Transform in transform) {
child.position += Vector3.up * 0.01;
other.gameObject.transform.parent=gameObject.transform;
gravity = 0;
}
}
//When the player exits the trigger
function OnTriggerExit(other : Collider) {
//Make the parent null/Over/Gone.
other.gameObject.transform.parent = null;
other.gameObject.transform.parent = null;
gravity = 20;
}
I also adjusted the gravity but its not needed, just a constructive helper. So Hope this Helped. ![]()
PS Just adjust the trigger a little to take out the bumpiness.