well, I got a problem with animatedsprite2D and collisionshape2D...
Asked Answered
C

17

0




what do I do?

Edit:
I just fixed the sprite.

Cilka answered 8/11, 2023 at 16:35 Comment(0)
C
0

Cilka what do I do?

Well, what do you want to do? Meaning, what exactly is the problem?

Coraliecoraline answered 8/11, 2023 at 16:53 Comment(0)
C
0

Coraliecoraline sorry! I mean, my collisionshape2d doesn't follow the animation.
there's any way to place a collision to each frame?
or move a specific frame or animation of a animatedsprite2D to a place in canvas?

Cilka answered 8/11, 2023 at 17:9 Comment(0)
C
0

Cilka Not that I am aware of, but I am no expert when it comes to animated sprites. Maybe you could play a normal animation at the same time of your sprite animation and move the position of the collider. But I am not even sure if that would work properly and also it's probably very fiddly.

But I wonder. Why does your sprite shift its position like that in the first place? Under normal circumstances it should be centered around its origin where the collider is.

Coraliecoraline answered 8/11, 2023 at 17:38 Comment(0)
C
0

Coraliecoraline idk, maybe is the position of the spritesheet.
i had some issues doing the sprites because it's, like, extremely low-poly. almost atari-like.

Cilka answered 8/11, 2023 at 17:56 Comment(0)
H
0

Cilka my collisionshape2d doesn't follow the animation.

My understanding that an AnimatedSprite2D is simply a series of images that are displayed. The engine doesn't know what's inside the images, and you can't make anything change based on that.

If you want to animate the CollisionShape2D's properties, you have to use an AnimationPlayer and Animation that changes those properties.

You could use the AnimatedSprite2D's signals, such as frame_changed, to perform actions.

Hyphen answered 8/11, 2023 at 17:57 Comment(0)
C
0

Hyphen do you recommend me to edit the spritesheet, or doing this? it's look a bit complicated.

Cilka answered 8/11, 2023 at 18:6 Comment(0)
H
0

Please explain your objective. It's not clear from your initial post.

Hyphen answered 8/11, 2023 at 18:10 Comment(0)
C
0

Hyphen my collisionshape2d doesn't follow the animation.
i just want to fit the character into the collision, or the collision into the animatedsprite2D.

Cilka answered 8/11, 2023 at 18:38 Comment(0)
H
0

Then an AnimatedSprite2D is not the right solution.

Hyphen answered 8/11, 2023 at 18:43 Comment(0)
U
0

You can adjust the collision shape with an AnimationPlayer, but whether or not this is a good idea is another question entirely. If it's some kind of transition like the character is switching from a run to a crouch that could make sense, but for something like a run animation it's usually best to keep the collision shape the same and make sure the animation roughly matches it throughout. If whether a player can make a jump or gets hit by an enemy depends on which frame of the run cycle they happen to be in that's likely to be confusing and frustrating.

Uncommunicative answered 8/11, 2023 at 18:55 Comment(0)
C
0

Hyphen I will try to fix the sprite.
but another question...

I use a this to my animation function:

func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D

if dir == "right":
	anim.flip_h = true
	if movement == 1:
		anim.play("side_walk")
	elif movement == 0:
		anim.play("idle_back")
		
if dir == "left":
	anim.flip_h = false
	if movement == 1:
		anim.play("side_walk")
	elif movement == 0:
		anim.play("idle_front")
		
if dir == "up":
	anim.flip_h = true
	if movement == 1:
		anim.play("back_walk")
	elif movement == 0:
		anim.play("idle_back")
		
if dir == "down":
	anim.flip_h = true
	if movement == 1:
		anim.play("front_walk")
	elif movement == 0:
		anim.play("idle_front")

it will flip the collision too?

Cilka answered 8/11, 2023 at 19:6 Comment(0)
C
0

Uncommunicative It's look easier to fix the spritesheet, so I'm trying that.
It's worth it?

Cilka answered 8/11, 2023 at 19:7 Comment(0)
H
0

Cilka it will flip the collision too?

Based on the documentation, that only flips the texture, not the node. Rotating the node 180 degrees should also rotate the collision shape, since that's a child of the node, but that may not have the result you want.

You could use two collision shapes, one for each flipped state, with one of them disabled. Toggle their disabled properties when you flip the sprite's texture.

Hyphen answered 8/11, 2023 at 19:20 Comment(0)
C
0

Cilka it will flip the collision too?

No but you can easily flip a node like a sprite by setting its scale.x value to -1. This will also flip (or: mirror around the origin) all its child nodes like for example a collider.

But just be careful. Generally speaking no matter if it's 3D modeling or messing with 2D/3D nodes like these in a game engine you should always be aware that changing the scale to something other than 1 might introduce some bizarre issues like unexpected physics or things like that.

In this case though it'll probably be fine.

Coraliecoraline answered 8/11, 2023 at 19:42 Comment(0)
C
0

Cilka Well, without knowing anything about this setup or how it even looks I'd say yes, it's probably best to fix the sprite.

Coraliecoraline answered 8/11, 2023 at 19:44 Comment(0)
C
0

Coraliecoraline thank you! I will take note on these.

Cilka answered 8/11, 2023 at 19:45 Comment(0)
C
0

Coraliecoraline looks functional to me, tho!

Cilka answered 8/11, 2023 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.