I am having problems with moving platforms in my 2D game and i can’t figure out what is causing the issue.
I have a gameobject that is moved via script. It contains the actual platform.
The platform itself has a box collider2d, a rigidbody2d (set to isKinematic) and a script attached to it. Objects that land on top of it are parented to the parent of the platform.
All things are doing what i want them to do. If the player jumps onto the platform he is parented to the platform container, same goes for boxes.
However if the player moves on the platform the movement is slower than usual.
The player is moved using
*float move = Input.GetAxis (“Horizontal”); *
myRigidbody2D.velocity = new Vector2(movemaxSpeed, ySpeed);*
If i debug.log the velocity, the numbers are the same whether i walk on the platform or on normal ground but on the platform the player is only about half as fast.
How the hell is that possible? What is going on?
------------------ EDIT -----------------------
so i am still going mad about this issue. I have found a way to move my objects with the platform without parenting them because i read on several threads that parenting to moving platforms is bad practise and can cause problems. The strange phenomenas are still happening though.
If you want to look into any of my code i will gladly share it. At the moment my next guesses for a potential origin of the problem are:
a) The player movement is manipulated in the FixedUpdate of the characterController script (with Input.GetAxis and then setting the velocity) and in the update function of my platform-Script (with transform.Translate). However when i parented the player in my old approach i didnt manipulate the movement anywhere but in the player’s FixedUpdate. In my platform script i only set a parent for it.
b) To detect wether or not the player is standing on the platform i am using OnCollisionEnter2D and OnCollisionExit2D. I am not sure how and why this would cause such an behaviour but i guess ill change this anyway since they do not seem to be called reliantly when the player hits the platform and i hope i can achieve a better result using raycasts.
I have already invested an incredible amount of time to get this fixed (around 20 hours of coding, testing, etc) so i hope i can get this fixed soon. Any help is highly apprecciated.