|
|
|
|
Reply From: |
bodicpen |
Hi there! Area2D is basically what its name is, an AREA. It’s mostly used for detecting collisions (detecting whether something entered an area, collided with an area, etc.) and while you can move this Area2D, it will not react to collisions but it may give you an output if you give it a script to do so.
You may want to replace the Area with a type of physics body (Kinematic, Rigid, Static)
Kinematic - this is used when you want an object to be solely controlled by you and its script.
Rigid - Rigid bodies are affected by physics whether they have scripts or not in them. Example, Angry Birds. You launch a bird to stones, wood, and pigs and they act like real physical objects in terms of falling, sliding, bouncing, rolling, and without scripts in them.
Static - this is commonly used for background and walls since it’s not affected by physics hence its name “static”. However, objects can still collide with this.
As for your game, I recommend using kinematic body since you want it to be controlled by a script (I assume moving 1 tile-space for a certain amount of time). However, you may want to add an area2d as a child of this kinematic body to detect collision so that when the area2d detects collision, it can tell its parent (the kinematic body) to stop moving either by setting the velocity, speed, or whatever variable you put in to 0, or you can just make a true/false flag like (Note, this is just a pseudo-code):
var can_move = true
func _physics_process(delta):
if can_move == true:
Insert your code of action here
func _on_Area2D_body_entered(body):
can_move = false
This means that in the beginning, the body can move but if another body (or area, depends on your game) touches it, the can_move will be set to false and will stop the body from moving.