I worked on a small fishing game in Godot for a Game Jam and as it was my first time creating something in Godot, for much of it I followed the Your first game tutorial from the Godot docs. In this tutorial, mobs are spawned from all sides of the screen, but for my game I wanted the fish to spawn only from the left and right side. Because of this change, instead of using one Path2d for the mob spawning, I used two straight lines on either side.
The lines were placed with the points in a clockwise order, so on the right side, the first point was the top and the second was the bottom, and on the left side, the first point was the bottom and the second was the bottom. Here is a picture that shows the spawning lines.
The mobs spawn and move in the correct direction, but no matter what I tried, the fish that spawned from the right side spawned with an incorrectly placed hitbox and with the sprite upside-down. This is an example of a fish that spawned from the left side, while this is an example of a fish that spawned from the right side.
Here is the code for spawning fish. Side is a variable that passed in and is simply 0 if the fish is spawning from the left and 1 if the fish is spawning from the right.
var fish = Fish.instance()
add_child(fish)
var fishSide
if (side == 0):
fishSide = $FishPathLeft/FishFollowLeft
else:
fishSide = $FishPathRight/FishFollowRight
fishSide.offset = randi()
fish.linear_velocity = Vector2(fish.speed, 0)
var direction = fishSide.rotation + PI / 2
fish.rotation = direction
fish.position = fishSide.position
fish.linear_velocity = fish.linear_velocity.rotated(direction)
When a fish is created, they are given a random base sprite from 4 possible bases, all of which have specific settings for the collision shape. The fish sprites default to facing left.
I assumed that the issue was because the fish is rotated 180 degrees when spawned on the right, but the problem is that even if I try to flip the fish, it still appears upside-down. I've tried flipping the fish with:
fish.scale.y = -fish.scale.y
But it doesn't seem to do anything, so I'm kind of at a loss as to what would fix it.