The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes


I'm working on a top-down shooter.

The mobs are KinematicBody2D objects that I am spawning. It is not a problem if I have to change the type.

They are following the player and eventually they will get on top of each other.

I want to avoid it. Looking around I found examples I can use to make them bounce but that's not what I want, I don't want them to take the same space.

Thank you.

enter image description here

in Engine by (24 points)

2 Answers

0 votes
Best answer

The problem was in my mob script. I was only changing its position and not checking for collisions.


func _physics_process(delta):
    position = position.move_toward(player.position, speed * delta) 


func _physics_process(delta):
    position = position.move_toward(player.position, speed * delta) 

I don't know if using Vector.Zero is the best or correct thing to do.

by (24 points)
0 votes

Well as long as you have collision shapes on your enemies and you make sure those collision shapes are looking at the same layer the enemy is on then they will bump into each other rather than go on top of each other.

by (3,328 points)

Thank's what I was expecting but I am missing something I can't find.

You see that the Mob (kinematicbody2d) has the collision layer and mask set to 1 (default).

The Area2D I am using to detect when a bullet hits it.

The CollisionShape2D is also using the default configuration.

In the Level scene I am spawning the mob like this:

extends Node2D

var mob: PackedScene = preload("res://scenes/Mob.tscn")
var spawn_time = 0

func _ready():
    spawn_time = randi() % 5 + 1

func _process(delta):
spawn_time -= delta

if spawn_time <= 0:
    spawn_time = randi() % 5 + 1

func spawn():
    var m = mob.instance()
    m.position = Vector2(randi() % 1024, randi() % 600)

enter image description here

On the collision shape in visibility is the collision shape also set to layer 1?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.