Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Vapor Trails

Heartfelt game about revenge (on Steam!) · By sevencrane

Moving platforms fix

A topic by wojk231 created Jun 28, 2023 Views: 134
Viewing posts 1 to 1

I noticed that the moving platforms are kind of buggy - when they're moving up, the character shakes, and when they're moving down and you're walking on them, you start falling right above the platform. I think i might have found a fix for that. You could parent the player to the moving platform they're on and remove the parent when the player gets off the platform. The code in the player script could look something like this:

private void OnCollisionEnter2D(Collider2D other){

    if (whateverConditionYouAreUsingForJumping && other.gameObject.tag=="whatever the tag is for the moving platforms"){ //if you can jump, you're on a platform (you can add an additional condition to account for double jumping)

        transform.SetParent(other.gameObject);

    }

}

private void OnCollisionExit2D(Collider2D other){

    if (other.gameObject.tag=="whatever the tag is for the moving platforms"){

        transform.parent=null;

    }

}


The capitalization in OnCollisionEnter/Exit and Collider2D might be wrong (I haven'tused Unity in a long time). The script should be inside the Player script. I'm assuming you're using Unity, because I saw it right after running the game.