├── .gitignore
├── LICENSE
├── README.md
└── addons
└── acro_hitboxes
├── hitbox.gd
├── icon.svg
├── icon.svg.import
├── plugin.cfg
└── plugin.gd
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Godot-specific ignores
3 | .import/
4 | export.cfg
5 | export_presets.cfg
6 |
7 | # Mono-specific ignores
8 | .mono/
9 | data_*/
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 AcroProjects
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Acro's Hitboxes v1.2
2 |
3 | Acro’s Hitboxes aim to streamline the process of generating knockback and damage from collision. This addon provides custom nodes that allow the user to apply knockback and damage to an object by changing the trajectory and strength of the knockback, allowing the user to visually see the launch angle and strength to reduce the amount of trial and error from traditional knockback methods, modify the length, width, and color of the hitbox, as well as enabling and disabling the hitbox.
4 |
5 | # Installation
6 |
7 | Copy `addons/acro_hitboxes` into your project (final path should be `res://addons/acro_hitboxes`). Open the Godot Editor, go to **Project Settings > Plugins** and enable the **Acro's Hitbox** plugin and click **Update**. You can now add a **Hitbox** node to a scene.
8 |
9 | # Variables
10 |
11 | ## shape (Shape2D)
12 | This variable can affects collision shape of the hitbox
13 |
14 | ## launch_angle (int)
15 | This variable will determine where an object will be launched if it is in contact with the hitbox
16 |
17 | ## strength (int)
18 | This variable will determine how far an object will be launch, which is properly shown in the editor with how long the launch angle line is
19 |
20 | ## damage (int)
21 | This variable can be used to return the amount of damage an object will take if it gets hit by a certain attack
22 |
23 | ## hit_stun (float,EXP, 0.001, 4096, .02)
24 | This variable returns a float that can be used for the hit stun of the hitbox. This variable is very similar to the "Timer" object
25 |
26 | ## knockback_scale (float, 0,1)
27 | This variable returns a float from 0 to 1 and is only used for advance calculations, such as if the user wants the amount of knockback an object to receive based on the amount of damage it has already taken
28 |
29 | ## disabled (bool)
30 | This variable works like the collisionshape2d button does (enables and disables the collision)
31 |
32 | ## reversed (bool)
33 | This variable inverts the launch angle on its X-Axis when it's set to true
34 |
35 | ## lineThickness (int)
36 | This variable changes the width of the launch angle line to make it easier for the user to see (for debugging purposes)
37 |
38 | ## draw_line_in_game (bool)
39 | This variable can enable the launch angle line to be drawn when the game is running (for debugging purposes)
40 |
41 | ## hitbox_color (Color, RGBA)
42 | This variable can change the color of the hitbox. Keep in mind, if the color of the hitbox is oddly colored, you’ll have to go into your project settings and change the Collision Shape Color to white
43 |
44 | # Methods
45 |
46 | ## get_launch_vector ()
47 | Calculates the launch vector to apply knockback automatically (without parameters)
48 |
49 | Returns:
50 | - Vector to apply knockback
51 |
52 | ## get_launch_vector (int launch_angle, int strength)
53 | Calculates the launch vector to apply knockback manually (with parameters)
54 | Parameters:
55 | - **launch_angle**: launch_angle
56 | - **strength**: length and width of the vector
57 |
58 | Returns:
59 | - Vector to apply knockback
60 |
61 | # Showcase Video
62 |
63 |
64 |
65 | # Support the project development
66 |
67 |
68 |
69 | # License
70 |
71 | - This is currently under the MIT, however, I (Austin Molina) have the legal right to change/modify the license if I conclude that the MIT License for **Acro's Hitboxes** is being abused by potentially harmful projects (Examples: Games that target a certain group of people, games that are political propaganda, Games that use NFTs or any other high energy used cyrto-tech, etc).
72 |
73 | MIT License
74 |
75 | Copyright (c) [2022] [Austin Molina]
76 |
77 | Permission is hereby granted, free of charge, to any person obtaining a copy
78 | of this software and associated documentation files (the "Software"), to deal
79 | in the Software without restriction, including without limitation the rights
80 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
81 | copies of the Software, and to permit persons to whom the Software is
82 | furnished to do so, subject to the following conditions:
83 |
84 | The above copyright notice and this permission notice shall be included in all
85 | copies or substantial portions of the Software.
86 |
87 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
90 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
91 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
92 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
93 | SOFTWARE.
94 |
--------------------------------------------------------------------------------
/addons/acro_hitboxes/hitbox.gd:
--------------------------------------------------------------------------------
1 | tool
2 | class_name Hitbox
3 | extends Area2D
4 |
5 | export(Shape2D) var shape = null setget update_shape
6 | export(int) var launch_angle setget update_la
7 | export(int) var strength setget update_st
8 | export(int) var damage setget update_da
9 | export(float,EXP,0.001,4096,.02) var hit_stun = 1 setget update_hs
10 | export(float, 0,1) var knockback_scale = 1 setget update_kb
11 | export(bool) var disabled = false setget update_en
12 | export(bool) var reversed = false setget reverseLaunchAngle
13 | export(int) var lineThickness = 1 setget update_lt
14 | export(bool) var draw_line_in_game = false setget update_vl
15 | # Color given as red-green-blue value (alpha will always be 1).
16 | export(Color, RGBA) var hitbox_color = Color(1,0,0,1) setget update_co
17 | #export(Array, int) var extraValues = [0, 0]
18 |
19 |
20 | # Called when the node enters the scene tree for the first time.
21 | func _ready():
22 | var collision = CollisionShape2D.new()
23 | collision.modulate = hitbox_color
24 | collision.set_shape(shape)
25 | add_child(collision)
26 |
27 |
28 | # Updates the collision shape of the hitbox
29 | func update_shape(newVal):
30 | shape = newVal
31 | for collision in get_children():
32 | collision.set_shape(newVal)
33 | update()
34 |
35 | # Updates the launch_angle of the hitbox
36 | func update_la(newVal):
37 | launch_angle = newVal
38 | update()
39 |
40 | # Updates the strength of the hitbox
41 | func update_st(newVal):
42 | strength = newVal
43 | update()
44 |
45 | # Updates the damage of the hitbox
46 | func update_da(newVal):
47 | damage = newVal
48 | update()
49 |
50 | # Updates the hit stun of the hitbox
51 | func update_hs(newVal):
52 | hit_stun = newVal
53 | update()
54 |
55 | # Updates the knockback scale of the hitbox
56 | func update_kb(newVal):
57 | knockback_scale = newVal
58 | update()
59 |
60 | # Enables and disables the hitbox
61 | func update_en(newVal):
62 | for obj in get_children():
63 | match newVal:
64 | true:
65 | obj.disabled = true
66 | false:
67 | obj.disabled = false
68 | disabled = newVal
69 | update()
70 |
71 | # Updates the line thickness of the hitbox IN THE EDITOR
72 | func update_lt(newVal):
73 | lineThickness = newVal
74 | update()
75 |
76 | func update_co(newVal):
77 | for obj in get_children():
78 | obj.modulate = hitbox_color
79 | hitbox_color = newVal
80 | update()
81 |
82 | # Updates if the line of the angle is visible
83 | func update_vl(newVal):
84 | draw_line_in_game = newVal
85 | update()
86 |
87 |
88 | # Calculates the launch vector to apply knockback automatically
89 | # @returns Vector to apply knockback
90 | func return_launch_vector():
91 | #Converts angle to radians
92 | launch_angle = launch_angle * PI / 180
93 |
94 | #Get X and Y components of vector
95 | var fx = strength * cos(launch_angle)
96 | var fy = -strength * sin(launch_angle)
97 |
98 | #Returns the vector of fx and fy
99 | match reversed:
100 | true:
101 | return Vector2(fx*-1,fy)
102 | false:
103 | return Vector2(fx,fy)
104 |
105 | # Calculates the launch vector to apply knockback manually
106 | # @param angle - launch_angle (int)
107 | # @param strength - length and width of the vector (int)
108 | # @returns Vector to apply knockback
109 | func get_launch_vector(launch_angle,strength):
110 | #Converts angle to radians
111 | launch_angle = launch_angle * PI / 180
112 |
113 | #Get X and Y components of vector
114 | var fx = strength * cos(launch_angle)
115 | var fy = -strength * sin(launch_angle)
116 |
117 | #Returns the vector of fx and fy
118 | match reversed:
119 | true:
120 | return Vector2(fx*-1,fy)
121 | false:
122 | return Vector2(fx,fy)
123 |
124 | # Updates the "reversed" variable
125 | func reverseLaunchAngle(newVal):
126 | reversed = newVal
127 | update()
128 | pass
129 |
130 | # Draws a line to show the knockback angle IN THE EDITOR
131 | func _draw():
132 | if not Engine.editor_hint and !draw_line_in_game:
133 | return
134 | draw_line(Vector2(),get_launch_vector(launch_angle,strength), Color('#ffffff'),lineThickness)
135 |
--------------------------------------------------------------------------------
/addons/acro_hitboxes/icon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/addons/acro_hitboxes/icon.svg.import:
--------------------------------------------------------------------------------
1 | [remap]
2 |
3 | importer="texture"
4 | type="StreamTexture"
5 | path="res://.import/icon.svg-410e9e59f18b5dfb25430255a2a8e272.stex"
6 | metadata={
7 | "vram_texture": false
8 | }
9 |
10 | [deps]
11 |
12 | source_file="res://addons/acro_hitboxes/icon.svg"
13 | dest_files=[ "res://.import/icon.svg-410e9e59f18b5dfb25430255a2a8e272.stex" ]
14 |
15 | [params]
16 |
17 | compress/mode=0
18 | compress/lossy_quality=0.7
19 | compress/hdr_mode=0
20 | compress/bptc_ldr=0
21 | compress/normal_map=0
22 | flags/repeat=0
23 | flags/filter=true
24 | flags/mipmaps=false
25 | flags/anisotropic=false
26 | flags/srgb=2
27 | process/fix_alpha_border=true
28 | process/premult_alpha=false
29 | process/HDR_as_SRGB=false
30 | process/invert_color=false
31 | process/normal_map_invert_y=false
32 | stream=false
33 | size_limit=0
34 | detect_3d=true
35 | svg/scale=1.0
36 |
--------------------------------------------------------------------------------
/addons/acro_hitboxes/plugin.cfg:
--------------------------------------------------------------------------------
1 | [plugin]
2 |
3 | name="Acro's Hitboxes"
4 | description="Custom node that allows the user to apply knockback and damage to an object"
5 | author="Austin Molina"
6 | version="1.0"
7 | script="plugin.gd"
8 |
--------------------------------------------------------------------------------
/addons/acro_hitboxes/plugin.gd:
--------------------------------------------------------------------------------
1 | tool
2 | extends EditorPlugin
3 |
4 | func _enter_tree():
5 | add_custom_type("Hitbox", "Area2D", preload("hitbox.gd"), preload("icon.svg"))
6 | pass
7 |
8 |
9 | func _exit_tree():
10 | remove_custom_type("Hitbox")
11 | pass
12 |
--------------------------------------------------------------------------------