Coder Social home page Coder Social logo

goutte / godot-addon-animated-shape-2d Goto Github PK

View Code? Open in Web Editor NEW
46.0 5.0 0.0 249 KB

Godot addon to animate a CollisionShape2D along with the frames of an AnimatedSprite2D. Useful for making changing hitboxes, hurtboxes and hardboxes. Comes with an Editor, making things easy.

License: MIT License

GDScript 100.00%
godot godot-addon godot-engine godot4 2d-game 2d-graphics game-development gdscript sprite-animation godot-plugin

godot-addon-animated-shape-2d's Introduction

Animated Shape 2D Addon for Godot

MIT Release FeedStarvingDev

A Godot 4.x addon that adds an AnimatedShape2D that can provide a custom shape for each frame of each animation of an AnimatedSprite2D.

It is useful to make custom hitboxes, hurtboxes, and hardboxes for each pose of your character, if you animated it using AnimatedSprite2D.

It comes with an Editor GUI to preview and edit your shapes, in the fashion of the SpriteFrames bottom panel.

A screenshot of the GUI showing a custom "Animated Shape" bottom panel in Godot

Features

  • customize a shape for each frame of your animations
  • configurable fallbacks
  • editor GUI, updated in real time
  • supports undo & redo where it matters
  • extensible

Install

The installation is as usual, through the Assets Library within Godot, look for AnimatedShape2D. You can also simply copy the files of this project into yours, it should work.

Then, enable the plugin in Scene > Project Settings > Plugins.

Usage

Please see the addons' README.


๐ŸฆŠ Feedback and contributions are welcome!

godot-addon-animated-shape-2d's People

Contributors

goutte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

godot-addon-animated-shape-2d's Issues

About making convex polygon shapes

This plugin is meant to be used along with a CollisionShape2D, and not a CollisionPolygon2D.

There is a Shape2D Resource named ConvexPolygonShape2D, but Godot's Editor is not activating a GUI to edit the points like it does for CollisionPolygon2D.

This is because the CollisionPolygon2D allows "concave" polygons by using multiple convex shapes internally.

How to generate a ConvexPolygonShape2D

  1. Create a CollisionPolygon2D
  2. Use the Editor to add/edit points
  3. Ensure you made a single convex shape
  4. Use the following Node to extract a ConvexPolygonShape2D from it.
@tool
extends Node
class_name CollisionPolygon2DConvexShapeExtractor


## Extracts a ConvexPolygonShape2D from a CollisionPolygon2D.
## THE SHAPE MUST BE CONVEX -- DO NOT MAKE CONCAVE SHAPES.
##
## Usage:
## - Add anywhere
## - Target an input polygon and an output shape
## - Reopen the scene in the Editor
## - Save the generated shape to a file using the Editor
##
## Be careful if you leave `shape` defined, it will write in it.


@export var polygon: CollisionPolygon2D
@export var shape: ConvexPolygonShape2D


func _ready():
	extract()


func extract() -> int:
	if polygon == null:
		push_error("CollisionPolygon2D is null")
		return ERR_CANT_ACQUIRE_RESOURCE
	
	if shape == null:
		shape = ConvexPolygonShape2D.new()
	
	shape.points = polygon.polygon
	
	return OK

Rename `AnimatedShape2D` into something else

A object worthy of the name AnimatedShape2D should extend Shape2D.
Preferably in C++. Doing its own thing, by the way, probably.

Let's not collide with that.


This addon provides a simple Node that couples an AnimatedSprite2D and a CollisionShape2D, using a database.

Ideas

  • AnimatedCollisionShape2D
  • CollisionShape2DAnimator
  • CollisionShapeFrames
  • AnimatedSpriteToCollisionShape2D
  • AnimationToCollision2D
  • AnimatedSprite2DCoupler
  • AnimatedSprite2DCollisions
  • โ€ฆ

Of note:

  • The Node should probably not end in 2D, since it is not a Node2D.
  • Yet it should not collide with 3D either, in the best of cases.

I'll let this sit for a while. (until v2)

Then we'll vote on the fedi. Probably using Majority Judgment.

Do chime in ; let's hear your name candidates !

Add a mouse-based GUI editor for shapes

Something that will show up in the main 2D editor like so :

image

There's a lot of things to do for such a feature.
But since I'm dogfooding this addon, I want this.

Improve onboarding

  • Make sure there are no errors when required properties are not set
  • Explain about required properties in the bottom panel
  • Update the bottom panel when AnimatedShape2D properties change

Not able to edit the shape at all

Hi,

I added your plugin, enabled it and then added the new AnimatedShape2D to my player node.
There I selected the animated sprite and collision shape and then added a new ShapeFrame.
image

When I now open the Animated Shape tab, the animations are listed, but when I click on them nothing happens
image

There's also a bunch of errors in my output log which might be related to that problem.
image

Do you have any suggestions on how I can fix that?

Help solving physics discontinuity

This addon works great for hitboxes and hurtboxes.

But for solidboxes, sometimes it creates glitches in the physics engine due to the discontinuity of the boxes.

Example:

inscrutable-2024-01-08_06.49.55.mp4

The character gets stuck because its solidbox goes from a small square to a much bigger rectangle in a single physics frame.


To mitigate this, this addon could perhaps enforce some continuity using tween or something akin, making sure that the dimensions (and position) of the collision shape do not change too much each physics frame.

UndoRedo history mismatch

This error message crops up when using the addon.

I'm not sure what we're doing wrong to warrant such an error.

I'll keep an eye out, but if you know why this is happening, please share.

Support for metadata on shape frames

This only needs a public endpoint to access the current shape frame, if any.

Rationale

I'm also using this plugin to add extra information on each animation frame, and it's been delightful for things like is_before_slash on startup frames.

Using this in AnimatedShape2D, and a get_meta on the result when not null:

func get_current_shape_frame() -> ShapeFrame2D:
	var animation_name := self.animated_sprite.get_animation()
	var frame := self.animated_sprite.get_frame()
	return self.shape_frames.get_shape_frame(animation_name, frame)

The metadata records are added in the Editor, as metadata of a single ShapeFrame2D. Shallow and deep copies seem to work as expected.

image

You don't have to use a special metabox to use Metadata, you can use the hitbox directly for example, but I've found it to be less messy.

Frame data shifting

Add two action buttons that move the targeted frame shape data to the left or to the right in the animation, pushing other frames as needed, and cancelling if there is no room.

Useful when one has added new sprite frames to the animation, and wants to update the shape data accordingly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.