Random Collision Error?

I have pads in my game that are moving up and down by using a

transform.Translate(Vector3.up*Time.deltaTime*12);

now this all works fine and the pads both move up and down, and both have box colliders but for some reason if the player stands of the pad and the pad moves upwards the player falls through the pad for some unexplained reason?

Why would the collider fail? is this because the pad is moving as the colliders never usually fail?

Full Code here

private var cPos : Vector3;
var lim : float = 10;
private var change : boolean;
function Start(){

    cPos = transform.position;

}
function Update () {
    if (change){
        transform.Translate(Vector3.up*Time.deltaTime*12);
    }else{
        transform.Translate(Vector3.up*Time.deltaTime*-12);
    }
    if (transform.position.y > (cPos.y + lim)){
        change = false; 
    } 
    if (transform.position.y < cPos.y){
        change = true;  
    }

}

The collider only fails when the object moves upwards

1 Answer

1

It's working for me man...

  private var cPos : Vector3;
  var lim : float = 10;
  private var change : boolean;
  var speed = 2;
  function Start(){

    cPos = transform.position;

  }
  function Update () {
    if (change){
      transform.Translate(Vector3.up*Time.deltaTime*speed);
    }else{
      transform.Translate(Vector3.up*Time.deltaTime*-speed);
    }
    if (transform.position.y > (cPos.y + lim)){
      change = false; 
    } 
    if (transform.position.y < cPos.y){
      change = true;  
    }

    if(Input.GetKeyDown("g")){
      speed++;
    }

  }

That;s exactly what I'm testing (Changed it to up, but does the same thing with the way you have it too)....

Might have to post all your code... Or tell us more about your actual scene.

the collider is moving with the object as well, I might that I am moving it up not right (my bad with the top post ill change it now) and the collider only fails when the pad moves upwards never downwards. I even tried putting other objects into the pad to act as separate colliders, whenever it moves upwards the all just fail.

Do you have a character collider on top of the pad? if so does he stay stationary? or drop through? Lastly maybe it is my code I will post it all you see the pad changes direction after a certain point in time?

The Problem seems to persist with a speed of 2 :(? I even tried it without the speed and just Time.deltaTime it still seems to just not have collision on the trip up and now if I land on the pad whilst it is moving up the player falls through?

I am working on unity iPhone so i sadly can't use your script, but basically I control the character who would be falling due to gravity using controls on the iPhone and he lands on the pad and if it's moving downwards he is fine, but if it is moving upwards he falls through I could try posting a screenshot just not sure how I would upload it to unity Answers? or would I need to host it somewhere and post the link?

I think I figured out the problem the collider on my pad doesn't push the collider on my character up as the pad moves up meaning after the pad moves past the character colliders skin (i figured this out by playing with the skin variable) the player would fall through as he is standing on nothing, Maybe I should write into my script that the player has to move up with the object? augh seems like a lot of work for so little >.<