I'm trying to get moving platforms to work. It seems like what I'm doing should be working in most cases, even if some corner areas fail.
I have a series of platforms that are told to rise upwards, then move back to a minimum height when they reach the maximum height. Each platform has a kinematic rigidbody, and a trigger-zone right above it. There's a crush-zone that kills the player when she hits the top.
The triggerzone seems to reliable parent the player to the platform as soon as they enter. But it does NOT reliably unparent them after they leave. Instead the character keeps trying to move upwards with the platform (although once they leave gravity interfers and results in them continuously hoping up and down).
The following code is what I'm using:
var target : Transform;
var cindyChar : Transform;
var minHeight = 0.0;
var maxHeight = 0.0;
var speedCoef = 3;
function FixedUpdate () {
if (LB_comboB_gear3.platformMove) {
if (target.transform.position.y < maxHeight) {
target.transform.position.y += speedCoef*Time.deltaTime;
}
if (Music.bigRhythmAble) {
if (target.transform.position.y > (maxHeight -.5)) {
target.transform.position.y = minHeight;
}
}
}
}
function OnTriggerStay (other : Collider) {
if (other.CompareTag ("Player")) {
cindyChar.parent = transform;
}
}
function OnTriggerExit (other : Collider) {
if (other.CompareTag ("Player")) {
cindyChar.parent = null;
}
}