0 votes

I have fixed a previous issue of mine, but there is slight jittering (not current problem) and the whole reason I implemented the navmesh is not functioning, since the enemy still just walks towards me apparently.

Here is the code for the enemy, I can provide screenshots, but I don't know how to upload my project.

other problems include the fact that i cannot use the ysort with the navmesh, they just dont work together?

Extends KinematicBody2D

const MOVE_SPEED = 190
const DETECT_RANGE = 200
const ATTACK_DIST = 100

onready var sprite = $Sprite
onready var anim = $AnimationPlayer
onready var nav = get_parent()
onready var raycast = $RayCast2D
onready var timer = $Timer


var path = []
var path_ind = 0
var player = null

func _ready():
    add_to_group("ninja")


func move_to(target_pos):
    path = nav.get_simple_path(global_position, target_pos)
    path_ind = 0

func _physics_process(delta):
    if player == null:
        return
    if player.global_position - global_position > Vector2(DETECT_RANGE, DETECT_RANGE):
        return
    if path_ind < path.size() :
        var move_vec = path[path_ind] - global_position
        if move_vec.length() < 1:
            path_ind += 1
        else:
            move_and_slide(move_vec.normalized() * MOVE_SPEED)

    var target = raycast.look_at(player.global_position)



func set_player(p):
    player = p


func _on_Timer_timeout():
    if player.global_position - global_position <= Vector2(DETECT_RANGE, DETECT_RANGE):
        move_to(player.global_position)

https://i.imgur.com/NwQxoBp.png

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Godot version 3.2.3
in Engine by (14 points)
edited by

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 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 webmaster@godotengine.org with your username.

Categories