Clips (.aeanim) and controllers (.aectrl) with importers, AnimationPlayer and Animator with crossfades, root motion and events on fixed steps, rewind support. Editor: Animation panel (dope sheet, curves, record, preview, trajectory), Animator panel, sprite sheet slicer and flipbooks, Programming workspace, export panel redesign. Motion 2D ledge climb. 11c: the component and Create palette.
79 lines
1.6 KiB
Plaintext
79 lines
1.6 KiB
Plaintext
package enemy
|
|
|
|
import "aego/math"
|
|
|
|
// Grunt patrols between two points and chases the player while it is close; its State Machine runs FixedPatrol or FixedChase and its Animator shows it.
|
|
script Grunt {
|
|
@export
|
|
var Player NodeRef
|
|
|
|
@export
|
|
var PointA NodeRef
|
|
|
|
@export
|
|
var PointB NodeRef
|
|
|
|
@export(min=0)
|
|
var SeeRange float = 4
|
|
|
|
@export(min=0)
|
|
var LoseRange float = 6
|
|
|
|
var toB bool = true
|
|
|
|
func Ready() {
|
|
node.Get<Health>().Died.Connect(OnDied)
|
|
node.Get<Animator>().StateEntered.Connect(OnState)
|
|
}
|
|
|
|
func toPlayer() Vec2 {
|
|
return Player.WorldPosition() - node.WorldPosition()
|
|
}
|
|
|
|
func FixedPatrol(dt float) {
|
|
goal := PointA.WorldPosition()
|
|
if toB {
|
|
goal = PointB.WorldPosition()
|
|
}
|
|
d := goal - node.WorldPosition()
|
|
if math.Length(d) < 0.2 {
|
|
toB = !toB
|
|
}
|
|
node.Get<Motion2D>().MoveDir(math.Normalize(d) * 0.5)
|
|
if Player != nil && Player.IsAlive() && math.Length(toPlayer()) < SeeRange {
|
|
node.Get<StateMachine>().Go("Chase")
|
|
}
|
|
}
|
|
|
|
func FixedChase(dt float) {
|
|
if Player == nil || !Player.IsAlive() || math.Length(toPlayer()) > LoseRange {
|
|
node.Get<StateMachine>().Go("Patrol")
|
|
return
|
|
}
|
|
node.Get<Motion2D>().MoveDir(math.Normalize(toPlayer()))
|
|
}
|
|
|
|
func EnterChase() {
|
|
node.Get<Animator>().SetBool("Chasing", true)
|
|
}
|
|
|
|
func ExitChase() {
|
|
node.Get<Animator>().SetBool("Chasing", false)
|
|
}
|
|
|
|
func OnDied(source NodeRef) {
|
|
m := node.Get<Motion2D>()
|
|
m.MoveDir(Vec2{0, 0})
|
|
m.Stop()
|
|
node.Get<Hitbox2D>().Deactivate()
|
|
node.Get<StateMachine>().Go("Dead")
|
|
node.Get<Animator>().SetTrigger("Die")
|
|
}
|
|
|
|
func OnState(state int) {
|
|
if node.Get<Animator>().StateName(state) == "Gone" {
|
|
node.Destroy()
|
|
}
|
|
}
|
|
}
|