Here is the code:
I don't understand how an engine knows the "body' node is a "Mob" node.
I didn't use a cast. I didn't set a Mob instead a Node class.
I had checked Node documentation and it doesn't know anything about the speed value.
Please help me understand. The code works fine. And What will be if our node does not have a speed variable?
The body_entered and exited signals of the Area2D node reports any physics body that enters or exits the area. In our project, it's necessarily a Mob.
Any node inherits from the type Node, whether it's a Sprite or a KinematicBody2D, or anything else. That's why you don't need to do a type cast or anything special to receive it as the body argument of the function.
So, the code works fine because what effectively enters the area is one of our mobs, and they have a speed property defined in their attached script.
If something that doesn't have a speed property enters the area, you'll see an error. Which is generally what you want in this case: the area should not be set up to detect something that's incompatible with its code, ideally.