Player slides off moving platform
Hi. This problem has already been discussed plenty of times but I still can't figure out something this simple.
I've got a player with a player controller. I've got a moving platform via DoTween, set to tween Rigidbody2d, working in Fixed Update. My platform is kinematic, my player is dinamic rigidbody, when it's on platform it becomes a child of it, when it leaves it's parent becomes null.
private void OnCollisionEnter2D(Collision2D player)
{
if (player.gameObject.name == "Player")
{
player.gameObject.transform.SetParent(transform);
}
}
private void OnCollisionExit2D(Collision2D player)
{
if (player.gameObject.name == "Player")
{
player.gameObject.transform.SetParent(null);
}
}
Though when on platform my player doesn't move with it and slides away. I tried moving platform with this:
private void FixedUpdate()
{
rb.MovePosition(rb.position + whereTo * Time.fixedDeltaTime);
}
Result is the same. I tried deactivating every script my player has, with no improvement. What else can I check/do to fix this? Why parenting doesn't work?
I think because it's kinematic not sure
Try making the script in user instead of platform so it can be kinematic.
Just guessing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613052534im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there an easy way to make a RigidBody2D collide with only one other RigidBody2D? 1 Answer
How to make instantiated rigidbodies continue moving the in the same direction as destroyed object? 1 Answer
RiigidBody2D.AddForce() isnt working at all. 0 Answers
Have one object apply a force to another. 0 Answers
2d Moving Platforms 1 Answer