+1 vote

Hi everyone :)
I'm currently making a 2D stealth game, including rooms, furniture(TileMap) and guards (KinematicBody2D).

I'm using Navigation2D, and getsimplepath to make the guards patrol around, but when they collide with any furniture- they get stuck.

I thought about a few ways to fix this, but the easiest one yet is to make the guards treat the furniture as walls, and use isonwall statement.
how do I do that?

And if you have a better idea, I would love to hear it, beacause I still havn't figured out how to walk around the furniture. The best idea I've got is to make the guards choose a different destination.

Thank you all in advanced!

in Engine by (151 points)

I think you cannot use isonwall because it determines something as a wall only for two directions while a furniture can be touch in any direction.

What are your using for ground?

Sorry it took so long for me to reply.
For the guard I'm using motion as Vector2, and moveandslide().
here's the script for the guard:

extends "res://Script/Character/NPCs/PlayerDetection.gd"

# Inheriting the following:
#const SPEED = 50
#const MAX_SPEED = 300
#const FRICTION = 0.25  # the time to get from MAX_SPEED to 0.

onready var navigation = get_tree().get_root().find_node("Navigation2D", true, false)
onready var destinations = navigation.get_node("Destinations")

var motion
var possible_destinations
var path =[]

export var minimum_arrival_distance = 5
export var walk_speed = 0.5

func _ready():
    possible_destinations = destinations.get_children()

func _physics_process(delta):

func make_path():
    var new_destination = possible_destinations[randi() % possible_destinations.size()     -1]
    path = navigation.get_simple_path(global_position ,     new_destination.global_position , false) 

func navigate():
    var distance_to_destination = global_position.distance_to(path[0]) 
    if distance_to_destination > minimum_arrival_distance:

func move():
    motion = (path[0] - global_position).normalized() * (MAX_SPEED * walk_speed)
    if is_on_wall():
        rotation_degrees += 90 

func update_path():
    if path.size() == 1 :
        if $Timer.is_stopped():

func _on_Timer_timeout():

Please log in or register to answer this question.

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.