Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mi1k |
I’m making a little space shooter/bullet hell type game and am now constructing the movement AI for the 1st enemy. They are supposed to rotate around the player for a few seconds and then move in for a burst rush towards the player.
I have the burst movement working, but I have no clue as to how I would go about having the enemy move in a circular motion around the target body.
This is my code for the movement so far:
extends "res://MOB.gd"
onready var parent = get_parent()
var is_moving = false
export (float) var turn_speed
export (int) var detect_radius
export (int) var spd
export (int) var dmg
export (int) var burst
var target = null
var is_atborder = false
var switch = false
var def = true
func _ready():
burst = 0
$Wait.wait_time = 2
$Detection/CollisionShape2D.shape.radius = detect_radius
func control(delta):
moving()
if target and def:
default_move()
chase_move()
func moving():
if is_moving == true:
$AnimatedSprite.play("movement")
else:
$AnimatedSprite.play("default")
func _on_Detection_body_entered(body):
if can_target:
target = body
func _on_Detection_body_shape_exited(body_id, body, body_shape, area_shape):
if body == target:
target = null
func default_move():
look_at(target.position)
#position = target.position + (position - target.position).rotated(90)
func chase_move():
if target and can_target:
def = false
is_moving = true
var dir = global_position.direction_to(target.global_position)
velocity = Vector2(speed, speed) * dir
can_target = false
burst += burst
$Timer.start()
if burst % 3 == 0:
$Wait.start()
func _on_Timer_timeout():
can_target = true
func _on_Wait_timeout():
def =true