In the video, after the jump on the monster, the movement and the sprite should still be facing the same direction. But instead it is moonwalking in the duration above. I ran into the same issue too. What causes that bug?
Hi,
Welcome to our community!
Could you please point me to the mark in the video where you saw the player(?) moonwalking?
7:37 to 7:39. THE MONSTER, not the player, is moonwalking. Thanks.
Now I see what you meant. Thanks for pointing me to the correct mark. I assume your EnemyMovement class looks like Rick’s.
If so, add the following lines to the method code blocks. Of course, add the Debug.Logs where it makes sense.
Debug.Log(Time.frameCount + " --- OnTriggerExit2D: Enemy collided with: " + other.name);
Debug.Log(Time.frameCount + " --- Update: Velocity was changed to: " + myRigidbody.velocity);
Debug.Log(Time.frameCount + " --- FlipEnemyFacing: Flipped enemy. Velocity: " + myRigidbody.velocity);
My theory is that there might be an issue with the synchronisation. FlipEnemyFacing is responsible for flipping the player but we do not set the velocity in OnTriggerExit2D but in Update. Update is not connected with OnTriggerExit2D and FlipEnemyFacing in any way.
When the problem occurs, check your console and find the OnTriggerExit2D message. Share the output from your console as of this method. I do not need to see the thousands of messages from the Update method. Only the messages in the context of the “moonwalking” are relevant.
Thanks Nina. Unity is kind of a side project to me and I probably wont be able to get to this soon since work got busy. I will get back to you once I have time to do so. Thanks again.
Thanks for the update!
It might be that this thread will be closed if you don’t come back within 20 days. That’s not a problem, though. Just message me or another moderator with a link to your thread, and we’ll be happy to re-open it for you.
Good luck with your other projects!
Hi Nina,
I am finally back.
Could you reopen the thread?
Here are the messages from the console that I think is related the the flipping:
26 — FlipEnemyFacing: Flipped enemy. Velocity: (2.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyMovement:FlipEnemyFacing () (at Assets/Script/EnemyMovement.cs:32)
EnemyMovement:OnTriggerExit2D (UnityEngine.Collider2D) (at Assets/Script/EnemyMovement.cs:24)
26 — OnTriggerExit2D: Enemy collided with: Ginger (Player)
UnityEngine.Debug:Log (object)
EnemyMovement:OnTriggerExit2D (UnityEngine.Collider2D) (at Assets/Script/EnemyMovement.cs:26)
26 — FlipEnemyFacing: Flipped enemy. Velocity: (2.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyMovement:FlipEnemyFacing () (at Assets/Script/EnemyMovement.cs:32)
EnemyMovement:OnTriggerExit2D (UnityEngine.Collider2D) (at Assets/Script/EnemyMovement.cs:24)
26 — OnTriggerExit2D: Enemy collided with: Ginger (Player)
UnityEngine.Debug:Log (object)
EnemyMovement:OnTriggerExit2D (UnityEngine.Collider2D) (at Assets/Script/EnemyMovement.cs:26)
They are all in 26 so I guess all of them happened in 1 frame?
Best,
O
Welcome back!
Yes, that’s correct. The enemy obviously collided with the player twice. There could either be two colliders attached to the enemy or player, or the flipping causes a second collision.
The velocity did not change. Was the scale changed?