Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to flip CollisionShape2D position together with Sprite in Godot?

A topic by Don4t45 created Oct 13, 2020 Views: 2,375 Replies: 3
Viewing posts 1 to 5


Hello,
How to switch sides of enemy's weak spot (collisionshape2d) when it approaches some cliffs and turns around?
I'd like to add one more collisionshape for worm's spikes with different effect on player, so my question is how to swap those two different collision shapes when sprite flips in order to kill the enemy by jumping on it's head, not it's spikes?
Moderator moved this topic to General Development

I wonder if this helps but ...Can't you just flip the parent Node2D.Transform2D directly? (There are even FLIP_X, FLIP_Y constants you may use)

https://docs.godotengine.org/en/stable/classes/class_transform2d.html

If you need another approach independent of using nodes and what Godot offers you, why not take all points from all collision shapes in the enemy, get most extreme values (highest and lowest coordinates) to obtain an overall center point for all shapes, and flip around it?. (Or even getting the sprite center point if that's your reference object).  

Hope this helps you find a solution.

Cheers!

(1 edit)

last night i figured out one way to achieve it :) the idea was to make an enemy with three different areas (weak spot[head], hurting spot[sides] and killing spot[spikes]), so i just added couple lines of code in func _ready(): and same two lines in _physics(delta):

but your way can be more sufficient probably. thanks, i really appreciate your answer




hello bud, this is super easy... the easy things are normally the most difficult to solve...

just set the scale of the whole node to minus i.e. if the scale is 3 then set  self.scale = Vector2(-3, 3)

this will flip the whole node, any movement will also be flipped too i.e. speed = -speed

hope this helps