Search Unity

Position Animationi/Moving Platform Solution using RigidBody Physics

Discussion in '2D' started by maxhap, May 16, 2014.

  1. maxhap

    maxhap

    Joined:
    Oct 24, 2013
    Posts:
    12
    Hey guys recently came across the titled problem and though I would post my solutions to help future people out. I found information regard in scares and personally didn't like the few solutions I found.

    I recently looked into creating a 2D moving platform that moved objects sitting upon it. A popular solution was to assign the objects as children of the platform when a collision was detected but from past experience this can often be hard to manage in different scenarios. I decided Physics was the best way to go, so I decided to use the rigid body and friction. I came across a solution of doing this using the RigidBody and RigidBody.MovePosition with a PhysicsMaterial however the 2D Rigidbody does not contain an implementation for MovePosition.

    So I decided to come up with my own solution. My solution allows for animations/tweens across multiple linked positions and moves the object using the RigidBody and Velocity so that any Physics2DMaterials or RigidBody Physics works correctly (manipulating the transform directly had strange physics effects).

    Heres the project on github
    https://github.com/maxhap/Unity3D2DTweenPosition.git
     
    Last edited: May 16, 2014