Created
December 16, 2020 09:27
-
-
Save Wolwer1nE/c0d1cc504c5a7a3542cb352c6de4dd0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Steering from "./steering.js"; | |
import Vector2 from 'phaser/src/math/Vector2' | |
export default class PatrollingLeftRight extends Steering { | |
constructor (owner, ownerSpeed= 80, force = 1) { | |
super(owner, force); | |
this.ownerSpeed = ownerSpeed; | |
this.lastX = owner.x; | |
this.currentDist = 0; | |
this.maxDist = Phaser.Math.RND.between(50, 150 ); | |
this.direction = 1; | |
this.started = false; | |
} | |
seek(owner, maxSpeed) { | |
const desiredVelocity = new Vector2(owner.x+maxSpeed*this.derection, 0) | |
.normalize().scale(maxSpeed); | |
return desiredVelocity; | |
} | |
calculateImpulse (currentBody) | |
{ | |
let pursuitMen; | |
pursuitMen = this.owner; | |
this.started= true; | |
const dx =Math.abs( this.lastX - pursuitMen.x); | |
this.currentDist += dx; | |
if ((dx < 2)||(this.currentDist>this.maxDist)) | |
{ this.derection *= -1; | |
this.currentDist = 0; | |
}; | |
this.lastX = pursuitMen.x; | |
return this.seek(pursuitMen, this.ownerSpeed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment