I am struggling with a character parenting on moving platforms in 2D game.
I’m using OnTriggerEnter2D() for a detection when player steps on the moving platform. It changes his parent to that platform. With common moving platforms (left-right) everything works fine, if a character stands on that platform he moves parallel with it, he can walk, jump etc. The problem appears when I use the platform that hangs on two ropes connected with HingeJoint2Ds. The player should swing that platform by walking left and right. When using a keyboard input everything works fine but with a touch-input controller, when player doesn't move, the character remains on one place and doesn’t move with that platform. In a hierarchy panel is everything correct, player is a child of platform and the platform is moving but character isn't.
For moving character I’m using this: (part of character controller)
float move = Input.GetAxis ("Horizontal”);
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
That’s the same for keyboard and touch input. Difference is only in the “move” variable getting. The solution for moving and swinging platforms is same too. (hierarchy, parents, colliders etc.)
I am struggling with this for several hours but I have no idea what could be wrong.
Thanks for any help.
What do you call a "touch input controller", is it a touch device? If so, are you sure Input.GetAxis("Horizontal”)
does anything on touch devices? won't it just return 0 always?
Have you tried logging your move
value, or copying it to a public variable to watch it evolve in the inspector? Maybe the values are orders of magnitude apart between one controller and the other, in which case you would need a multiplier.