• 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

[Lập trình game] Lesson 11: Godot’s Raycast2D Enemy – Part 2

AnonyViet by AnonyViet
February 2, 2023
in Tips
0

In this article, I will guide you to create raycast2D so that the enemy can move on the terrain as shown below without falling down. And let’s get started

Join the channel Telegram of the AnonyViet 👉 Link 👈

[Lập trình game] Lesson 11: Godot’s Raycast2D Enemy – Part 2

RAYCAST2D EASY

programming Enemy Raycast2D

Here Raycast 2D is 1 node: Query object intersecting ray means Raycast 2D is 1 ray and this ray is used to query object when intersecting ray

ENEMY

Next is the enemy you enter the enemy’s sence

Find yourself raycast2D

Raycast2D

And be like this

Raycast2D code

Here you do not use the mouse but use the right arrow key to move it to the edge collsionshape

And almost as open as me

[Lập trình game]  Lesson 11: Godot's Raycast2D Enemy - Part 2 6

On the side of the nature, pay attention to yourself Enable and Cast to

live Enabled you click for yourself and raycast will turn blue

[Lập trình game]  Lesson 11: Godot's Raycast2D Enemy - Part 2 7

LIVE cast to part y you cast it close under the enemy

[Lập trình game]  Lesson 11: Godot's Raycast2D Enemy - Part 2 8

Like the picture, this enemy is too small so I’ll adjust the scale raycast wall 0.5, 0.5

And after adjusting the scale, you also have to adjust the other part

[Lập trình game]  Lesson 11: Godot's Raycast2D Enemy - Part 2 9

Next we will code it

And Coding for me

Below if is_on_wall

You add yourself as

if $Raycast2D.is_collding == false:

vitri = vitri * -1

Here $Raycat2D is called raycast2d || is_collecting is the command: Returns whether any object is intersecting the vector ray which here we attach = false means it will not intersect at all.

And vitri = vitri * -1 here means the enemy will move in reverse when on the terrain that I mentioned at the beginning of the article

And you notice when it has moved back but this raycast2D it doesn’t move back anymore so we need to adjust it.

You add $RayCast2D.position.x *= -1 into the if is_on_wall and raycast collecting Please

This is the help command Raycast 2D can change direction and you can apply to other nodes like collsionshape etc

It is done

And remember to delete *delta let’s go

If the code does not run, the code is as below

Full code godot Raycast2D

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

Tags: EnemyGameGodotslậpLessonPartRaycast2Dtrình
Previous Post

Share Key Avast SecureLine VPN until 2021 – Multi-Server VPN Software

Next Post

[Lập Trình Game] Lesson 10: Creating Enemies in Godot Programming – Part 1

AnonyViet

AnonyViet

Related Posts

5+ prompts to create sparkling Christmas photos for mothers and babies at home
Tips

5+ prompts to create sparkling Christmas photos for mothers and babies at home

December 17, 2025
How to Clean Up Your Computer to Speed ​​Up Windows Faster
Tips

How to Clean Up Your Computer to Speed ​​Up Windows Faster

December 16, 2025
Share Snowfall Code for Website to celebrate Christmas
Tips

Share Snowfall Code for Website to celebrate Christmas

December 16, 2025
How to build web applications in just minutes with Youware
Tips

How to build web applications in just minutes with Youware

December 15, 2025
5 Free Adobe Illustrator Alternatives on Linux
Tips

5 Free Adobe Illustrator Alternatives on Linux

December 15, 2025
Review of Chongluadao utility – HieuPC’s new anti-fraud utility
Tips

Review of Chongluadao utility – HieuPC’s new anti-fraud utility

December 14, 2025
Next Post
[Lập Trình Game] Lesson 10: Creating Enemies in Godot Programming – Part 1

[Lập Trình Game] Lesson 10: Creating Enemies in Godot Programming - Part 1

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

5+ prompts to create sparkling Christmas photos for mothers and babies at home

5+ prompts to create sparkling Christmas photos for mothers and babies at home

December 17, 2025
How to Clean Up Your Computer to Speed ​​Up Windows Faster

How to Clean Up Your Computer to Speed ​​Up Windows Faster

December 16, 2025
Share Snowfall Code for Website to celebrate Christmas

Share Snowfall Code for Website to celebrate Christmas

December 16, 2025
How to build web applications in just minutes with Youware

How to build web applications in just minutes with Youware

December 15, 2025
5+ prompts to create sparkling Christmas photos for mothers and babies at home

5+ prompts to create sparkling Christmas photos for mothers and babies at home

December 17, 2025
How to Clean Up Your Computer to Speed ​​Up Windows Faster

How to Clean Up Your Computer to Speed ​​Up Windows Faster

December 16, 2025
Share Snowfall Code for Website to celebrate Christmas

Share Snowfall Code for Website to celebrate Christmas

December 16, 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

5+ prompts to create sparkling Christmas photos for mothers and babies at home

5+ prompts to create sparkling Christmas photos for mothers and babies at home

December 17, 2025
How to Clean Up Your Computer to Speed ​​Up Windows Faster

How to Clean Up Your Computer to Speed ​​Up Windows Faster

December 16, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

trang chủ f168 nhà cái 78win https://www.qq8827.com/ https://go99.ae.org/ https://nohu90.bid/

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

trang chủ f168 nhà cái 78win https://www.qq8827.com/ https://go99.ae.org/ https://nohu90.bid/

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply