How do i make the enemy turn at the edge?
I’m following brackeys youtube tutorial on how to make a game since im new but im trying to add aspects of my own sort of.
How do i make the enemy slime turn at the edge so he doesn’t walk away into space? I don’t know if i should add something in my script or add some other nodes.
Depends how universal you want the solution to be.
If you want enemies to walk off some ledges but not others, add a detection box and tell the enemy to turn around if it touches it.
If you want all enemies to never walk off ledges, you could:
a. do the same thing as above but everywhere
b. child a ground detection box under each enemy’s feet and a little in front, and if the box no longer overlaps with solid ground, have the enemy turn around.
That’s just two ways of doing it. I’m sure there are more advanced ways but for a small project these solutions should work fine.
(Note that this requires both script and nodes. I might be able to write up an example, but it depends how those ground cubes actually work internally)
I want it everywhere for now since im just learning.
the ground cubes idk really i got them from brackeys on youtube but i right now have some other areas where the enemy turns when they hit a wall/cube using RayCasts on each side.
Right now this is what it looks like. Should i code it so like if the CollisionShape is about to get off the edge it turns around?
if is_on_floor( ): or something like that in the script?
If your trigger is is_on_floor() that means it would only turn around after it walked off. That doesn’t look great. If we’re doing raycasts I’d go for one that looks down at the ground in front of it, and if there’s no collision it turns.
Or you could place a vertical ‘gap’ marker that gets detected the same way as a wall would - unless it’s detecting physics collision in which case it’ll have to check for something else.
You have to get used to the contacts in Godot. Even if you decide to design the entire thing with just standalone code. You will be met with forced nodes and uses around the node. Maybe learn that a little bit. Characters, bodies, areas, the actual collisions and their shape. They all have their applications. For example, some guy here on the forum asked how to turn off gravity for a Character. Because the character is falling. How? He asked. Because the collision shape has the gravity disabled. Apparently the character body has it’s own gravity scale in Godot. Last chance, maybe Godot is not right for you?
Try to maybe apply layers before you make changes. Always a good start. It makes it easier to separate your characters and where they go. It’s very JRPG. It usually separates players from offscreen enemies. ANd, how they’re allowed to behave.
Small thing but it’s never the last chance. Do what you want.
Learning to code comes with learning to learn to code. If you don’t made a game in Godot but learn a bit about Godot, that knowledge is still at least partially applicable elsewhere. No time is truly wasted!
More on topic, yes, the menus are almost as big a thing in this engine as the code you actually write. I recently got C++ error messages because it automatically set a node’s ‘skeleton’ to a node I removed. All good but watch out for it and learn how that can work for you rather than against you.
if ray_cast_right.is_colliding() or not ray_cast_right_ground.is_colliding():
direction = -1
if ray_cast_left.is_colliding() or not ray_cast_left_ground.is_colliding():
direction = 1
It doesn’t matter. The problem is this person may not understand the Godot concept. All the script functions are predefined for node types just like the UI. If a character has physics and transform interference for UI so will the code. Similarly if you try to apply interferences from other nodes they fail. LIke move() only for character. gravity_scale() only for rigid bodies. YOu can’t change that. Not, it Godot script anyway. I seen some changes in C# for self centered syntaxes. It’s kind of compared to C++'s anytaxes. It’s just made to do the opposite of what the syntaxes do and perform their own looks and calls. BUt, he doesn’t need that. He’s already working with a pretty nice small package. It is a little buggy.