playMaker

Author Topic: Help : Enemy AI: chasing a player without Navigation2D or A* pathfinding !  (Read 1086 times)

siumanchunandy

  • Playmaker Newbie
  • *
  • Posts: 28
Hi :

https://abitawake.com/news/articles/enemy-ai-chasing-a-player-without-navigation2d-or-a-star-pathfinding

How to convert to Playmaker Action Logic ?

func _init(enemy, params):
  chase_target()

func chase_target():
  var look     = enemy.get_node("RayCast2D")
  look.cast_to = (enemy.target.position - enemy.position)
  look.force_raycast_update()

  # if we can see the target, chase it
  if !look.is_colliding():
    enemy.dir = look.cast_to.normalized()

  # or chase first scent we can see
  else:
    for scent in enemy.target.scent_trail:
      look.cast_to = (scent.position - enemy.position)
      look.force_raycast_update()

      if !look.is_colliding():
        enemy.dir = look.cast_to.normalized()
        break

func _physics_process(delta):
  var motion = enemy.dir * enemy.speed
  enemy.move_and_slide(motion)

Thanks !

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
the sample is for godot not unity, also the coding does not look like c#
maybe find a sample for unity :)

siumanchunandy

  • Playmaker Newbie
  • *
  • Posts: 28
Yes, Godot is not unity!
But Logic should be convertible to Playmaker FSM Logic ?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Hi.
Maybe this is useful (hes using an asset, but it would save you a lot of time (+headache) with this)