Thank_47
Thank_47

Reputation: 1

Why isn't my sprite's CollusionShape2d not changing horisontally in Godot

The AnimatedSprite2d is changing horizontally but the CollusionShape2d isn't, here is the code:

if direction == 1:
        $AnimatedSprite2D.scale.x = 1
        $CollisionShape2D.scale.x = 1
    if direction == -1:
        $AnimatedSprite2D.scale.x = -1
        $CollisionShape2D.scale.x = -1

How can I fix it?

I tried changing it to flip.h but it threw me an error that it was out of scope, also my collusion shape is a rectangle.

Upvotes: 0

Views: 228

Answers (1)

MeSteve95
MeSteve95

Reputation: 131

It is generally a bad idea to change the scale of physics objects, and CollisionShape2D is no exception.

To get around this, try changing how you approach the problem to avoid resizing the collision shape at runtime. Some ways you could accomplish this are:

  • Keep the collision shape the same at all times.
    • Change the visuals/movement of your character so that the collision shape and visuals always match.
  • Toggle different collision shapes for different contexts.
    • Create multiple collision shapes that have different sizes/positions/etc., and then toggle these collision shapes on/off depending on the context.

Hopefully one of these solutions work for you!

Upvotes: 0

Related Questions