Bug Fix on Model Flip

Fixing the sprite flip on player and enemy models

While working on the hitbox animation for the Moss Giant, I noticed that all sprite models that require to flip on the X axis does so without the hitbox flipping as well.

The hitbox not flipping with the Moss Giant Model

This causes some bad interactions when the player is on the left side of the all enemy models. As I dwell deeper I also noticed that the Player model also suffers from this same problem. Since the hitbox is a special case with no sprite renderer, we are unable to use the Renderer FlipX function when the model needs to flip.

Fixing the Problem:

The logic behind the solution is quite simple, instead of flipping just the sprite when either the enemy is near the point destination or required to face the player, we can instead flip the entire parent object which houses both the sprite and hitbox.

Player Script:

Within our Player script we would need to replace our Sprite Renderer with the parent object which we will targeting the Transform component. We can call this new variable “_playerFlip”.

With the Sprite Renderer commented out, we will also need to comment out the methods that require the Sprite then we are going to use the Transform component and place a -1 on the X scale value. This negative value would cause the entire game object to flip including the sprite and hitbox.

The proper script would be using the local scale and giving the transform component a new Vector3 value where only the X axis changes to the negative 1.

Now you can see that the player flips according to the direction along with the hitbox. We can apply the same method for the Enemy Parent script.

Enemy Script:

In the Enemy script we are going to do the same thing by targeting the parent game object and it’s Transform component we can flip the entire model including the hitbox.

In the enemy script we are going to use “Protected” instead of “private”
In the Enemy Movement script when going to pointA to pointB

In within the facing player method, we can use the same method for flipping the model.

As you can see from the result on the bottom, we have successfully fix the issue, and all models including the player will flip accordingly.




A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Headless WordPress made easy with Gatsby

How I Created A Twitter Bot with Node.js

Mac-like Gestures on Ubuntu 20.04 Dell XPS 15

⑥②⑧⑦.⑤⑥.④⓪⑧③. CRYSTAL/LOAN/CUSTOMER/CARE/NUMBER ⑥②⑧⑦.⑤⑥.④⓪⑧③.

Getting started with Node.js and delion.io to use IOTA Tangle

Tail-kit : 200+ free Tailwind components / templates

Step 5: Functions! Part 2/ Zero to Front End Dev

Single Page Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Learn to code by making 2 D space shooter.

Let’s Make A Player

Jumping in between two walls in Unity

2D Mobile: Designing Enemies Using Abstract Classes