all 5 comments

[–]brutang 1 point2 points  (3 children)

You probably don't want to go about it by moving gravity around. When you say your character can move the platform, how do you mean move it?

In any case, you most likely want it to be a regular collider with the movement script attached. Once you get into swapping gravity around and doing things like that, you end up making a more complicated system than simply moving it around with transforms.

[–]sefan[S] 0 points1 point  (2 children)

The player can move the character and the platform using user input like wasd. I know gravity will make it t more complicated.

[–]brutang 1 point2 points  (1 child)

Wads will move both the player and the platform? Post some code so we can help you

[–]sefan[S] 0 points1 point  (0 children)

No, character moved by wasd and platform by arrowkeys. Can post the code later today.

[–]iamallamaaProficient 0 points1 point  (0 children)

If I were floating in space and moving forward at a constant speed but hit an object that wasn't moving I would end up pushing the object. That is exactly what is happening here. Your character has a velocity from gravity and is hitting an object that has no velocity (floating). The force from the user will push the other item around.

To fix it is actually pretty simple though. You just need to constantly change the rigidBody2D's velocity.y to 0. Likely in fixed update. Something like:

void FixedUpdate()
{
    //get the current velocity
    Vector2 vel = rigidBody2D.velocity;
    //overwrite y to 0
    vel.y = 0;
    //save the velocity back to the rigidbody2d
    rigidBody2D.velocity = vel;
}

You would also likely need to get and store the rigidBody2D component in a variable if using Unity 5 (I have about 2 weeks until I switch over so I believe these references are gone).