• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

[Godot RPG] #3: Attack & Object

AnonyViet by AnonyViet
February 1, 2023
in Tips
0

Welcome to lesson 3 in the series of RPG game programming with Godot :3

Join the channel Telegram of the AnonyViet 👉 Link 👈

Okay, in this post I will guide you to attack with animation player & Hitbox & Hurtbox and Object with Godot

And let’s get started

Attack

We will create a new Sense to be a Hitbox to check when we attack and a hurtbox to check that when the hitbox it collides, it loses health.

Hitbox & HurtBox

Create the Hitbox and the root node is Area2D and then add the CollisionShape2D.

[Godot RPG]  #3: Attack & Object 35

Then create a new script

[Godot RPG]  #3: Attack & Object 36

Here I will use the export variable to export to the Inspector for easy adjustment for each character. You can change the language outside of Godot’s interface to Vietnamese for easy

[Godot RPG]  #3: Attack & Object 37

Then save it and you’re done.

Then create a new Sense as HurtBox then save it as Hitbox and don’t need to create a script because we will connect the signal to the player

[Godot RPG]  #3: Attack & Object 38

Tap then hit

We have to check if we click to attack. You can Edit the Input, if you’re lazy, use it like a picture :vv. Godot has many options!

[Godot RPG]  #3: Attack & Object 39

Then the status will be equal to ATTACK.

In ATTACK: we will create a new function called trangthai_attack which will have code to run animtion attack

[Godot RPG]  #3: Attack & Object 40

Then next you call it on ATTACK: okay.

Then when attacking we have to set speed = 0 so that when attacking it won’t move

[Godot RPG]  #3: Attack & Object 41

After the attack is done, it will stay still because it has not returned to the IDLE state so we have to set it back.

I will create a new function

[Godot RPG]  #3: Attack & Object 42

Then in AnimationPlayer > Animation AtTACk > add track method (this is the track that will run the Godot function which has this convenience :3)

[Godot RPG]  #3: Attack & Object 43

Then choose Player because the Player only has the code to run:

[Godot RPG]  #3: Attack & Object 44

Then select the function

[Godot RPG]  #3: Attack & Object 45

Then adjust it to the end because at the end of the animation = run the function

[Godot RPG]  #3: Attack & Object 46

And so you will move normally again

Instance & Animation Player

Next we will Instance it in Godot. Instance I don’t even know what to call Vietnamese anymore@@.

Then click add 2 Hitbox & Hurtbox then right click on 2 click Editable as children so we can adjust it as a child node and set collishape too.

[Godot RPG]  #3: Attack & Object 47

Well before that, we have to set the mask/layer first. Go to Project > Project Setting > 2D Render / 2D Physics

Please set like me. Set for both 2D Render and 2D Physics

[Godot RPG]  #3: Attack & Object 48

Then in the player’s Hitbox on the attribute table > collision, I will uncheck the layer and in the Mask will tick it to collide with Hurtbox_E ie when the player attacks it will collide with the enemy’s hurtbox.

[Godot RPG]  #3: Attack & Object 49

[Godot RPG]  #3: Attack & Object 50

Then in the HurtBox Layer, you tick the box Hurtbox_P in the blank mask

[Godot RPG]  #3: Attack & Object 51

Next is to adjust the CollisionShape2D of HurtBox to fit the character.

[Godot RPG]  #3: Attack & Object 52

Then next will set collisionshape2D of Hitbox with AnimationPlayer.

In Hitbox’s Collisionshape2D, click on the key to add a quick track

[Godot RPG]  #3: Attack & Object 53

[Godot RPG]  #3: Attack & Object 54

You will then position when it attacks to turn it off/on.

Since it hasn’t attacked yet, I will leave Disabled = true at 0 seconds and then check the next few seconds if it comes to attack action, set disable = false and then after withdrawing the sword, disabled = true

[Godot RPG]  #3: Attack & Object 55

[Godot RPG]  #3: Attack & Object 56

Then run it again and it will be fine and perfect :33. I love this in Godot

Object

Next we will create object with Godot.

Download link: https://elthen.itch.io/pixel-art-destructible-objects

Create a new Sense

Here, create:

Area2D > Sprite – CollisionShape2D – AnimationPlayer

[Godot RPG]  #3: Attack & Object 57

In the sprite, please put the image in and I think it’s a bit big, you should set the scale accordingly.

Vframes = 12

Hframes = 7

[Godot RPG]  #3: Attack & Object 58

If not, then reimport it.

[Godot RPG]  #3: Attack & Object 59

Then next in AnimationPlayer create 2 animations Hit and Destroy. Hit is the hit animation and Destroy is the destroyed animation.

Here I will be the Box you want to change.

Hit : 7-9

Destory:10-13

In animation destroy I will apply the same call method above.

destroy() contains the queue_free() statement

[Godot RPG]  #3: Attack & Object 60

Then create a new script. here we don’t need Hitbox or Hurtbox because this box is already an area2d node.

we will set collisionshape2D for it and then connect the signal. but note that if you follow the area2D Button like me, you will be at a disadvantage when the player collides with it. If you use StaticBody to make it and then add Hurtbox to it, it will be better.

Connect signal Area enterd offline.

[Godot RPG]  #3: Attack & Object 61

I will create the variable hp = 10 to have the base when the player attacks.

Then in the signal function, I will check if the name area = “Hitbox”, then the hp will be equal to the damage of the area minus hp. The print is what I use to check the HP to see if I have entered it, Godot.

[Godot RPG]  #3: Attack & Object 62

Then set the Layer to Hurtbox_E and uncheck the Mask.

[Godot RPG]  #3: Attack & Object 63

Next we need to check if the player attacks it will stop the animation hit and when the health runs out run the animation destroy

Here I will function _process(): to check every second if hp <= 0 then it will run animation and then self-destruct

[Godot RPG]  #3: Attack & Object 64

Then Next to make sure you are at ANimation hit, click the circle below the image so that when it starts it runs the animation hit, not destroy.

[Godot RPG]  #3: Attack & Object 65

Note: Object was stupid at first, so I sympathize :V. When running the game Ọbject will not collide with the player, if you want you have to change it to StaticBody2D or KinematicBody2D and then add hurtbox > connect the signal and then apply the above code.

See you in the next article of the series of RPG game programming with Godot

The article achieved: 5/5 – (100 votes)

Tags: AttackGodotobjectRPG
Previous Post

FILEminimizer Pictures 3 Full Key – Compress images without loss of quality

Next Post

Attack the Bootrom system of the net shop

AnonyViet

AnonyViet

Related Posts

Tips to fix the file is open in another program
Tips

Tips to fix the file is open in another program

May 21, 2025
7 ways to release RAM to accelerate your Windows computer
Tips

7 ways to release RAM to accelerate your Windows computer

May 21, 2025
The 10 best Torrent websites today – 100% still operate
Tips

The 10 best Torrent websites today – 100% still operate

May 20, 2025
Share Code Shop Selling Acc game extremely lightweight written in bootstrap
Tips

Share Code Shop Selling Acc game extremely lightweight written in bootstrap

May 19, 2025
Display the Internet speed on Windows Taskbar with Du Metter
Tips

Display the Internet speed on Windows Taskbar with Du Metter

May 18, 2025
Interesting facts about Google that you don’t know
Tips

Interesting facts about Google that you don’t know

May 17, 2025
Next Post
Attack the Bootrom system of the net shop

Attack the Bootrom system of the net shop

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Guide to comment on the constitution amendment on VNEID

Guide to comment on the constitution amendment on VNEID

May 21, 2025
Tips to fix the file is open in another program

Tips to fix the file is open in another program

May 21, 2025
7 ways to release RAM to accelerate your Windows computer

7 ways to release RAM to accelerate your Windows computer

May 21, 2025
Discover Supermix – Smart playlist on YouTube Music

Discover Supermix – Smart playlist on YouTube Music

May 20, 2025
Guide to comment on the constitution amendment on VNEID

Guide to comment on the constitution amendment on VNEID

May 21, 2025
Tips to fix the file is open in another program

Tips to fix the file is open in another program

May 21, 2025
7 ways to release RAM to accelerate your Windows computer

7 ways to release RAM to accelerate your Windows computer

May 21, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Guide to comment on the constitution amendment on VNEID

Guide to comment on the constitution amendment on VNEID

May 21, 2025
Tips to fix the file is open in another program

Tips to fix the file is open in another program

May 21, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso